tags:

views:

256

answers:

5

I got involved in a new project where Perl is a must. I'm coming from a good Ruby foundation and want a quick introduction or mapping between Perl and Ruby as I heard that Perl and Ruby are very close in syntax (know nothing about features).

  1. Do you have any recommendations for me?
  2. What great Perl book do you recommend as an extended reference?
  3. What is the commonly used version of Perl right now?
+4  A: 

Do you have any recommendations for me?

Perl.org is a good site to get some resources

What great Perl book do you recommend as an extended reference?

Programming Perl and Learning Perl are very nice, but also take a look here

What is the common used version of Perl right now?

Depends of your platform, take a look here

Nathan Campos
+16  A: 

I second Nathan's book recs, though I would also mention Beginning Perl. Two bonus features are (1) it's available freely (and legally) online in its first edition (note: this site is timing out right now, and I'm unsure if that's temporary or not) and (2) it covers about as much as Learning Perl and Intermediate Perl combined. A con is that it's at times more elementary that you might want. (Learning Perl goes faster and assumes a bit more - which can be a good thing.)

You might also check out this: To Ruby From Perl from Ruby's website. Just think of it in reverse.

In terms of versions, 5.10.1 is stable, but you will come across a range. Mostly you will find 5.8.x and up, I suspect. (Just as with Ruby 1.9.1 is stable but you will find plenty of places still using 1.8.6 or up.)

Since I'm somewhat going in the opposite direction (I know Perl reasonably well, and I'm using Ruby more and more often), I can mention things that stick out to me:

  1. In Perl, you get automatic conversion between strings and numbers (and you don't need to explicitly ask for a float result by using .to_f or making one item a float).
  2. Semicolons are not optional to end statements in Perl. Similarly parentheses are optional less often in Perl than they are in Ruby. (This gets complex quickly, but for example you must have parentheses for the test in a condition or a while block.)
  3. 0 (string, integer and float), undef and the empty string evaluate as false in boolean tests.
  4. There are no separate booleans true and false.
  5. You distinguish data types with sigils: $foo is a scalar; @foo is an array; %foo is a hash. (Arrays in particular will bug you: they aren't instance variables.)
  6. You need to explicitly scope items in Perl, using the my keyword.
  7. Arrays in Perl are automatically flattened when combined. (This constantly bites me in Ruby.)
  8. Context, context, context. In Perl an enormous amount of what your code actually does depends on understanding what context you're in. Here's a link for a start, but it's a big topic with a lot of nooks and crannies.

(Note that I didn't mention the 1000 pound gorilla in the room. OO is part of what Perl is and can do, but it's not at the center of Perl, as it is in Ruby.)

Telemachus
The problem with the link to *Beginning Perl* was temporary: http://log.perl.org/2009/10/fuel-pump-fail.html
Telemachus
For OO perl, learn Moose http://search.cpan.org/perldoc?Moose::Cookbook ...
singingfish
Moose certainly makes the rubyometer twig a little bit :)
hobbs
can you clarify what you mean in item 5 about arrays not being instance variables? complex variables in most languages are passed by reference and it is up to the programmer to clone the object if necessary. perl is no different in ths regard, is ruby?
Eric Strom
Eric Strom: He's pointing this out because in Ruby sigils denote scope. So a @var in Ruby is similar to a "my" var in Perl.
mpeters
@Eric: I was warning Khelll about a visual ambiguity. In Ruby, `@variable` indicates something about the scope of a variable (it's an instance variable), but in Perl the `@` tells you immediately something about the data type (it's an array). If you move from one language to the other, the shift in visual cues can be jarring - to say the least - at first.
Telemachus
Thanks, that makes sense and shows how little ruby i've seen, but i guess its good to have the clarification here.
Eric Strom
@ does not mean array in Perl. It means multiple items, as in @hash{@keys}.
brian d foy
+13  A: 

Versions

In The Perl Survey 2007***, the majority of Perl coders used Perl 5.8, with 87% using 5.8.x at least some of the time, and 5.8.8 being the most common single version. A minority used 5.6.x for at least some projects, and a smaller (but occasionally quite vocal) minority uses 5.005. Since that point Perl 5.10 has been released and it's not clear yet what the adoption rate is; likely many businesses are being conservative and running 5.8.8 or 5.8.9, but many of what you might call "prominent hackers" are using 5.10.1 and even sometimes requiring its features.

References

  • Programming Perl is a winner for anyone with previous programming experience who wants to get up to speed on Perl quickly. The current edition is the third, which corresponds (unfortunately) to Perl 5.6.0.
  • The series Learning Perl, Intermediate Perl, Mastering Perl is also recommended; Learning Perl starts off rather slow because it targets beginners, but it eventually covers all of the major features of the language, including some that didn't exist in 2000 when Programming Perl was last revised.
  • Perldocs. Please, don't neglect the perldocs. The master index is at perldoc perl, or you can read online at perldoc.perl.org. These are nearly as good a reference as Programming Perl because in fact a decent portion of that book is drawn from the Perldocs. I would recommend at least a thorough skim of perlsyn, perlop, perlrun, perlvar, perlre, perlobj, perlmod, perluniintro, perlreftut, and perldsc. Reading straight through perlfunc once isn't a bad idea either.
  • Effective Perl Programming is a book I've always recommended for learning how to approach problems with a Perl frame of mind. Its 1998 publication date limits its usefulness a bit but I still think it's worth a read -- and fortunately, brian d foy and Josh McAdams are working on an updated edition, due (I think -- don't trust me too far on this) March 2010. [And the second edition is now here -- brian]
  • Perlmonks is a great resource, especially if you remember to use the search feature. A great many questions have been asked and answered there, and the best answers are indexed for posterity, along with lists of resources such as books and online FAQs.

*: I would love to provide a link to The Perl Survey 2007 but unfortunately the perlsurvey.org domain was allowed to lapse. A copy of the results PDF may be found at github, and the mostly-raw data is on CPAN as Data::PerlSurvey2007.

hobbs
A great post (the survey results are very helpful), but I have to disagree with one thing. *Learning Perl* emphatically does *not* cover "all the major features of the language." As a start, it doesn't cover these: references, OO in Perl, um - references, complex data structure (see references). I pretty much recommend that anyone buying *Learning Perl* also buy *Intermediate Perl* immediately, unless they plan only to write only shortish scripts.
Telemachus
You got me there. Maybe *Beginning Perl* is a better recommendation since it gets more in-depth, but I was always put off by its writing/teaching style.
hobbs
@Hobbs: Don't get me wrong, I love *Learning Perl*. I just think it's part one of a two-part feature film.
Telemachus
Perlsurvey 2007 (and the planned next one) can be found on Github: http://github.com/singingfish/perl-survey-2009 The 2007 report can be found there (PerlSurvey2007A4.pdf).
draegtun
+4  A: 

People keep telling me Picking Up Perl is dated and they are right but it is such a concise introduction that I would recommend reading it and then jumping straight into Intermediate Perl and Perl Best Practices as well as Perl Cookbook. The Cookbook is great if you learn by better by concrete, bite-sized examples.

Further, I really recomend reading the FAQ List before doing anything else.

Sinan Ünür
If you're a fan of somewhat idiosyncratic introductions to Perl, I also like *Learning Perl the Hard Way*. The author offers a pdf freely or you can buy a dead-tree version from Lulu: http://www.greenteapress.com/perl/
Telemachus
@Telemachus I like that book.
Sinan Ünür
A: 

I recommend "Programming Perl", "Perl Best Practices" and the "Perl Cookbook" also.

The "PBP" book is good, not because it teaches you rules, but because it makes you stop and think about why you should do things a certain way, and make an educated decision when you decide to stray from Conway's recommended path.

As for documentation, I often use CPAN's documents as they're the most current and offer hyperlinks, something we don't get from the local perldocs on our drive.

One of the things I loved about Ruby when I first started using it compared to Perl, was gems vs. CPAN. Keeping a set of gems current seems so much easier than a set of CPAN-based modules.

And, like Sinan says, the FAQs are great reading. I've read and reread them many times because the knowledge is good to keep in your head.

And, though they can be rather blunt, the PerlMonks are a wonderful resource. Simply searching and reading how they recommend doing things can raise your Perl consciousness several levels, even if you don't engage them with a direct question.

And, in the way of the monk, contemplate Perl's hashes and learn about slicing them. They are the shiz.

Greg