I consider myself quite fluent in PHP and am rather familiar with nearly all of the important aspects and uses, as well as its pratfalls. This in mind, I think the major problem in taking on Perl is going to be with the syntax. Aside from this (a minor hindrance, really, as I'm rather sold on the fact that Perl's is far more readable), what are some key differences you think I should make myself aware of prior to taking on the language?
views:
383answers:
7some different things worth a read about:
- packages
- lexical scopes
- regular expression syntax
- hashes, arrays and lists (all the same in PHP, all different in Perl)
- CPAN
Perl is great for file processing, extractions, regex. It is the first tool I would pick for any kind of text processing.
Although the terse syntax makes Perl quite difficult to read, the power of its inbuilt regex and file processing makes it well suited for small programs which would actually be much larger in traditional languages.
I had been using Perl for a very long time before doing any PHP, and I found the transition fairly easy.
The syntax is very similar between PHP and Perl. Obviously there are differences and you have to learn a new set of libraries (CPAN has modules for most uses, so before you implement any new tools have a look at CPAN).
Regexs are less verbose and imo a little easier to use in Perl. On the other hand classes in PHP looks a more like what you would expect if you know other OO languages. To me OO in Perl seems a little tacked on.
After you learn the basics of Perl, I highly recommend the book "Perl Best Practices" by Damian Conway.
It really changes your writing style, and the way you think about programming, and in particular, makes your Perl programs much more readable, and maintainable.
At this point of the game, Perl still makes for an excellent quick-n-dirty parser applications. For any language you shouldn't really worry about syntax cleanliness unless you're using the language well outside the scope of what it was meant for. Perl has been given a bad reputation because of it's notorious leaning toothpick syndrome. Most of this is because l33t script kiddies like to condense 5 lines of Perl code on 1 line.
As a side note C + Perl =~ m/PHP/
use strict;use warnings;
Perl::Critic, perltidy (in future)
CPAN (use CPAN shell to install them)
To use more modern OO system than current Python-based one, you need to install OO system from CPAN. Try Moose (or Mouse if Moose is too powerful for you).
Unicode is different (integrated into language)
'eq' and '==' instead of ==/===/strval/intval (important)
test orientation (start with Test::More)
Also see Perl programming wiki - tutorials and other useful links.
Well for web stuff look at Catalyst. For OO stuff look at Moose. For best practices, follow some of the advice elsewhere in the thread. That should be enough to get you started.