|
Posted by Toby A Inkster on 06/13/07 08:19
peter wrote:
> thanks guys. it was useful. Being from a UNIX background, I found perl
> intuitive :) if php is c++ like, I dont think I would care for it. I
> shall see if others contribute more later.
I would say that PHP is more Perl-like than C++-like. I started PHP with a
background in Perl and found it very easy to pick up.
Here's an example to demonstrate their similarities.
Perl:
#!/usr/bin/perl
$a = 1;
$b = 1;
$c = undef;
$psi_old = undef;
print "Approximating psi...\n";
while (1)
{
$psi = sprintf('%.08f', $b/$a);
last if ($psi_old eq $psi);
$psi_old = $psi;
print "$psi\n";
$c = $a + $b;
$a = $b;
$b = $c;
}
PHP:
<?php
$a = 1;
$b = 1;
$c = NULL;
$psi_old = NULL;
print "Approximating psi...\n";
while (1)
{
$psi = sprintf('%.08f', $b/$a);
if ($psi_old == $psi) break;
$psi_old = $psi;
print "$psi\n";
$c = $a + $b;
$a = $b;
$b = $c;
}
?>
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 109 days, 15:48.]
URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
[Back to original message]
|