Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Preaching Perl gospel to PHP converts...

by broquaint (Abbot)
on Apr 24, 2002 at 15:59 UTC ( [id://161657]=note: print w/replies, xml ) Need Help??


in reply to Preaching Perl gospel to PHP converts...

1. What does Perl have that PHP does not?
In terms of language it has features such as closures, lexical scoping and flexible syntax. As an interpreter it is at home on the command-line, 'easy' to embed, *very* portable and pretty speedy (see. The Great Computer Language Shootout for some interesting comparisons). Something the perl community has over the PHP community is it's maturity and cohesiveness. That's not to mention it's immense library that will probably cater to every need.

2. Alternatively, what does PHP have that Perl doesn't?
It has an extensive API built into the language, with everything from zip functions to complex data structure manipulation. It has very nice documentation which is comprehensive and a dream to navigate. The language itself is quite consistent and mostly straight-forward, and because it was designed with the web in mind you can embed your code right in the page (if you so wish to do so).

3. What does Perl do differently than PHP?
One of the first things you'll notice coming from PHP is that regex is stuck right in the code without any ereg or preg functions wrapped around. This in itself shows perl's origins as a *nix command-line tool, so it adheres a lot to the *nix methodology. Something that will really trip up converts is the way perl deals with lists. Everything from assigning to returning from a function can be confusing and frustrating, so it's a good idea to get that sorted out ASAP. Then there's references which are used frequently within perl programs, whereas you can write entire websites in PHP and not use a single reference. PHP only has dynamic scoping, so pretty much *everything* is a global (unless it's in a function or a class). Something that always confused me in PHP which I thought perl did so much better is the way it deals with arrays. In PHP you can treat and mingle indexed and associative arrays and call associative arrays like indexed arrays. Whereas perl has a clear distinction between arrays and hashes in terms the way they're used, so $hash{foo} can *never* be called $hash[0].

4. Common pitfalls that PHP converts face the first time they start praticing Perl?
As I mentioned earlier, the way perl deals with lists can be confusing. References can also be a mis-understood and are subsequently ignored in favour of passing everything in named data structures (which then leads on to 'list confusion'). Another pitfall is lexical scoping (but I declared it just *there*!!!) where in the PHP world once you've declared a variable it isn't going anywhere quickly. Possibly the biggest mistake a PHP programmer will make is not using strict, as it throws up too many forboding and annoying errors for the uninitiated.
HTH

_________
broquaint

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2024-03-19 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found