tags:

views:

383

answers:

7

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?

+15  A: 

some 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
Cal
I would also recommend learning what the different sigils represent, although that's easy to learn and remember. If I remember correctly, PHP has only the '$' while perl has multiple sigils in addition to '$'.
gpojd
good point! $a vs @a vs $a[1] vs %a vs $a{foo}
Cal
+3  A: 

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.

Cade Roux
It's not terse syntax that can make it difficult to read, it's the natural language like syntax that does that.
singingfish
It's its terseness and natural language like syntax that makes it powerful. What makes some Perl code difficult to read is the programmer who wrote it, same as in any language.
MkV
+4  A: 

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.

Brian Rasmussen
Classes are more flexible in Perl, and if you want to go the whole hog on OO, Moose/Mouse is more OO than most OO languages.
MkV
+10  A: 

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.

Tom Feiner
+1 - This book has changed my life.
cowgod
on the other hand about 1/2 of perl best practices is best ignored. It's left as an exercise to the reader which part is. (but use Moose and ignore the chapter on Inside Out Objects is a useful pro-tip)
singingfish
Very true. There's a lot of good advice in the book, good sounding advice, and stuff you should probably avoid. There's a good list of them here: http://www.perlfoundation.org/perl5/index.cgi?pbp_module_recommendation_commentary
Robert P
A: 

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/

Jeremy Edwards
"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" <- what do you mean by this, it doesn't make much sense to me at all.
singingfish
+3  A: 
  • 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.

Alexandr Ciornii
s/powerful/slow and resource hungry/
MkV
A: 

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.

singingfish