Reply to Re: php and perl

Your name:

Reply:


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
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация