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


In reply to Re: Preaching Perl gospel to PHP converts... by broquaint
in thread Preaching Perl gospel to PHP converts... by vladb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.