|
Posted by Jerry Stuckle on 06/13/07 15:49
Toby A Inkster wrote:
> 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;
> }
>
> ?>
>
C/C++:
#include <stdio.h>
float a = 1.0;
float b = 1.0;
float c = 0.0;
float psi_old = 0.0;
puts ("Approximating psi...");
while (1) {
psi = b/a;
if (psi_old == psi)
break;
psi_old = psi;
printf ("%f\n", psi);
c = a + b;
a = b;
b = c;
}
Of course, C++ has many OO features the C doesn't have.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|