19

I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it the other way around.

My main concern is not about the language itself (I think that part is always easy), but about learning the Perlish (as contrasted with Pythonic) way of doing things; because I don't think it'll be worth the effort if I end up programming Python in Perl.

So my questions are basically two:

  • Are there many problems/application areas where it's actually more convenient to use Perl rather than Python?
  • If the first question is positive, where can I found a good place to get started and learn best practices that is not oriented to beginners?
Community
  • 1
  • 1
fortran
  • 74,053
  • 25
  • 135
  • 175
  • "There's more than one way to do it" is a Perl motto, which pretty much means that anything goes for *Perlish*. – MattH Mar 25 '10 at 14:09
  • 9
    That's not true at all @MattH. Perl definitely has it's own idioms that are preferred over other ways of doing things. Just because there are multiple ways to attack the same problem doesn't mean that one of them isn't more *Perlish* than the others. – mpeters Mar 25 '10 at 14:20
  • 4
    All the pigs in Perl are equal... but some are more equal than others :) – DVK Mar 25 '10 at 14:50
  • @DVK, four legs good, two legs better. – daotoad Mar 25 '10 at 14:53
  • 1
    @DVK nooooooo!!! *All animals are equal. Some (i.e. the pigs) are more equal*. http://www.youtube.com/watch?v=NZldlyeR8DU&feature=fvw – Sinan Ünür Mar 25 '10 at 16:41
  • 3
    @Sinan - heh. My version's more idiomatic Perl than Orwell's :) – DVK Mar 25 '10 at 16:50
  • 2
    There's a reason people are moving away from Perl. It's an atrocity of a language. Spend an hour or two to learn it well enough for quick commandline hacks (`perl -ne 's/a/b/; print;'`)--it's better than sed and awk for that. Any more is nothing but brain pollution. – Glenn Maynard Mar 26 '10 at 07:36
  • 1
    @Maynard I liked perl, and for "quick-and-dirty" stuff is great to me, better than Python (which has some oddities I can't stand, and other cool stuffs often I don't need). Each lang is what it is to people able to use it proficiency, and I hope perl-as-I-know-it (none of Perl6) won't die – ShinTakezou Jun 26 '10 at 10:03
  • 1
    @Maynard --- I can't learn *any* language very well in an hour or two. Let alone well enough to accurately assess its capabilities. C++ used to look like line noise to me, now it makes sense. Same goes for Python --- it made little sense until I forced myself to use it for real projects. – Mick May 29 '12 at 15:57

6 Answers6

17

One area where Perl is more "convenient" is using it for one liners. Python can be used to produced one liners, but often its "clunky" (or ugly). Note that Perl is renowned for its "terseness" or "short and concise", often at the expense of readability. So coming from Python, you have to learn to get used to it.

Another area is Perl's vast number of modules in CPAN. The equivalent of that is Pypi but its modules are not as many as CPAN.

that said, both do similar things and both have their own merits.

As for your second question, you can look at Perl documentation. I find it very useful. Especially also read the Perl FAQ. They are the best resource for myself if I want to learn about Perl.

ghostdog74
  • 327,991
  • 56
  • 259
  • 343
  • 1
    Specifically, have a look at `perldoc perlstyle` and look at the chapter in the Camel book on writing idiomatic perl (statements like `next if $xyz;` are very Perl-y and idiomatic.) –  Mar 25 '10 at 15:50
  • 5
    Perl's FAQ is absolutely huge. Half the perl language specific questions on SO could probably be answered simply by just looking at the FAQ. :) – Robert P Mar 25 '10 at 20:35
  • 3
    Perl is also very good at multi-line lambdas, Python has to use one-liners there. – MkV Mar 26 '10 at 08:12
15

For best practices, check out Perl Best Practices by Damian Conway. Not all of the recommended practices make sense, but most of them do.

The Perl::Critic module also helps with best practices.

Also, check out the Modern Perl Books blog.

If you have questions, Perlmonks is the best web forum to get help. There are a large number of very knowledgeable, friendly people who can, and will, answer your questions and discuss the merits of different approaches.

daotoad
  • 26,689
  • 7
  • 59
  • 100
11
AndyG
  • 39,700
  • 8
  • 109
  • 143
draegtun
  • 22,441
  • 5
  • 48
  • 71
  • Develop using Moose, deploy with Mouse and Any::Moose – MkV Mar 26 '10 at 08:11
  • 1
    @james2vegas: I've never used Mouse or Any::Moose. I always just stick to Moose with no issues thus far. NB. For other readers of this comment... Mouse is a lightweight Moose by excluding the Meta Object Protocol (Class::MOP). – draegtun Mar 26 '10 at 19:32
  • 1
    @james2vegas: re: Aspect / AOP - Yes I believe this is a full on AOP implementation in Perl. Whereas I think Moose more embraces (bits of) AOP rather than enforcing it. – draegtun Mar 26 '10 at 19:34
4

I think Learning Perl from O'Reilly Media is a pretty good way to get started with Perl, even if you are already proficient in Python.

Especialy if you want to get to know the one-liner stuff (and this is what Perl is REALLY good at)

Powertieke
  • 2,368
  • 1
  • 14
  • 21
  • LP is a great book to get started with even if you are an experienced programmer. It's very well written and not painful to skim to "get to the good bits". – daotoad Mar 25 '10 at 15:55
4

Impatient Perl

One of my favorite books for people who want to learn it and then get stuff done is Impatient Perl by Greg London, a free netbook available from perl.org. If you're a programmer, know scripting, know the concepts behind dynamic languages, and just want to know how perl does it, this is a great starting resource.

Robert P
  • 15,707
  • 10
  • 68
  • 112
3

Effective Perl Programming is mostly for people who know the basics of Perl's syntax but need to learn the idioms. We also cover similar stuff in our Effective Perler blog :)

brian d foy
  • 129,424
  • 31
  • 207
  • 592