Slashdot Mirror


Learning Perl, 4th Ed.

Craig Maloney writes "Just about everyone out there who has ever typed #!/usr/bin/perl has encountered Learning Perl (otherwise known as "The Llama Book") in one form or another. You may have learned some of the intricacies of the language from this tome, or you've seen someone recommend this book to potential Perl programmers on-line. Learning Perl is generally in the top three recommended books for new Perl programmers, next to Programming Perl ("The Camel Book"). Now in its fourth edition, Learning Perl returns with updates covering the stable 5.8 series of Perl. The changes are subtle, but the improvements make for a clearer and more readable book." Read on for the rest of Maloney's review. Learning Perl, Fourth Edition author Randal L. Schwartz, Tom Phoenix and brian d foy pages 304 publisher O'Reilly rating 9 reviewer Craig Maloney ISBN 0596101058 summary The fourth edition of the classic text for learning the Perl language.

When I was initially introduced to Perl, I was one of those who was recommended to read Learning Perl. I picked up the initial edition (with the mauve binding), and began my journey into Perl. What I found was a dense, hard-to-follow introduction to the language, with the experienced Perl programmer in mind. I realized that the tutelage of this experienced programmer/author might be useful, but I opted for other books instead. As others looked to me for book recommendations, I recommended other works for people looking to immerse themselves in Perl, and relegated Learning Perl to the section of my library where live books with a steep learning curve (similar to the learning curve experienced by many with Kernighan and Ritchie's classic The C Programming Language). Like The C Programming Language, however, a full grasp of the language is not achievable from texts where the central focus is to avoid using the lingo and customs of those who are more familiar with the language. Only by full immersion in the culture of the language can one become fully proficient in that language. What's new? Learning Perl 4th edition has been updated in several ways from the previous edition. The text has been updated to reflect Perl 5.8, although this book doesn't introduce any 5.8 specific concepts. The new edition was reorganized from the previous version. The chapter on Regular Expressions is enhanced, and file handles are introduced in the I/O Basics chapter. CPAN is introduced in Learning Perl, since it has become much more important to beginners. The chapter on flat-file databases (DBM/DBM Hashes) didn't make the cut for this edition, but a good portion of the chapter made its way into Chapter 9 (Processing Text with Regular Expressions). The book has a cleaner feel to it, and flows without the erratic feel of the previous editions. What's good Learning Perl could rightly be called A Tourist's Guide to the Perl Culture. The material is immersive, and teaches Perl using the verbal language of a Perl programmer. No attempt is made to dumb down the material. This leads to sentences in the book like the following: Alas, these aren't words as you and I are likely to think of them; they're those \w-type words made up of ordinary letters, digits, and underscores. The \b anchor matches at the start or end of a group of \w characters. The previous sentence makes perfect sense for those who have already grasped the fundamentals of regular expressions, but for those who aren't quite up to speed, the previous sentence warrants further study. This can be a blessing or a curse for some. Ultimately, it forces the reader to understand the Perl culture which can only improve the reader's understanding of Perl. Also of note are the footnotes. Almost every page in the book contains footnotes commenting (sometimes sarcastically) about the topic at hand. Sometimes the footnotes can be distracting, as your eyes will busily look for the next humorous footnote, such as this little gem: And /,{5}chameleon/ matches "comma comma comma comma comma chameleon". By George, that is nice. What's Bad The only complaint I can level at Learning Perl is that there could be more explanation for some of the concepts in the book. In the section called "More Regular Expressions," the book presents the following example:

Here's the text:
I'm talking about the cartoon with Fred and Wilma!
And here's a substitution to remove those tags. But what's wrong with it?
s#(.*)#$1#g;
The problem is that the star is greedy. What if the text had said this instead?
I thought you said Fred and Velma, not Wilma
In that case, the pattern would match from the first to the last , leaving intact the ones in the middle of the line. Oops! Instead, we want a non-greedy quantifier. The non-greedy form of star is *?, so the substitution now looks like this:
s#(.*?)#$1#g;
And it does the right thing.
Unfortunately the less astute reader may not understand what exactly happened here. One line of output with the end result would help clarify what this regular expression did.

What's in it for me? Learning Perl would rightly be regarded as one of the classic texts for Perl programmers to read through at least once in their Perl careers. The book is chock-full of useful information, and even experienced Perl coders would do well to at least leaf through the pages of this book for paradigms to help their coding. Absolute beginner programmers would likely find this text a little over their heads, but intermediate programmers will find Learning Perl a valuable resource in their road to proficiency with Perl. You can purchase Learning Perl, 4th Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

14 of 172 comments (clear)

  1. Perl6 is a mistake by Anonymous Coward · · Score: 2, Informative
    I've been using perl pretty much constantly since the Pink Camel, and believe me, Perl 5 is an extremely good language for quick scripting things. That's what it was designed for. Sure, you can do big projects in it, but it's not exactly ideal. Recently I've started using Ruby as well, and I intend to move my department over to it instead of wasting time with Perl 6.

    One of the goals of Perl 6 is to make non-trivial projects possible. That's good. The way it's being done is bad. Perl was once a lightweight, extremely flexible language. Now it's become a huge ugly monster. People wanted OO, so a nasty hack was bolted on top to allow some semblance of it. Now this nasty hack is being expanded. Sure, the code's different, but the basic form is the same. Kludge upon kludge upon kludge; I'd much rather have a nice, clean, pure language (and not one with loads of irritating whitespace thank you very much).

    The same goes for the syntax. All the switching between $, @ and % is really irritating (ask a newbie how to get at the length of the keys array of a hash inside a hash, for example), and the changes proposed for 6 are just making this worse -- it seems that Larry, in his infinite wisdom, wants to prefix every data type with a different hard-to-type character. Perl was only designed for the three data types, and adding more is a mess.

    Perl 6 is a complete rewrite, but it keeps all the mess which has accumulated over the previous versions. This is not good. Sure, my const int $var = 27; may look neat (in the same way that, say, Pascal does), but $var isn't entirely constant, or entirely an integer, it's just a hack which makes it sort of behave like one. The whole thing is an exercise in pseudo-computer science masturbation with little real purpose except to please the managers who dislike the one thing that makes Perl special.

    On a similar note is regexes. I'm an avid fan of regular expressions simply because a nondeterministic finite automata is far more flexible than linear code. However, Larry must have been smoking that cheap $2 crack when he wrote this. Does he want Perl 6 to be flex or something?

    I won't be going on to use 6. It's a nice idea, but it's completely unnecessary. It won't make large projects any easier to manage (the language is still, at heart, an almighty hack -- an impressive one, but still a hack). It won't make OO any cleaner. It won't make development any faster. To put it bluntly, Perl scripts will still look less beautiful than our friend Mr Goat.cx. I'd prefer to use a language which has always been pure synthesis of science and engineering, not some half-baked imposter.

    Perl 6 will be nice, but I'm guessing it will be the end of Perl. It can't do what it wants to do whilst still being based upon a nasty mess. There are now other options, which provide all of Perl's power and none of the mess. Sorry, but *BSD^H^H^H^H Perl is dying. Larry is buggering it up the ass without lubricants, just like Shoeboy is doing to Larry's daughter.

  2. Hated it by jafac · · Score: 3, Informative

    While, ultimately, I'm reserving Perl as a skill ONLY used when absolutely necessary (ie. when I get stuck debugging someone else's code) - I didn't like Learning Perl, or Programming Perl, or Perl in a Nutshell. All three of these books left me frustrated and completely lost.

    In sharp contrast, the Perl Cookbook, gave me answers to all of my questions. I recommend Perl Cookbook to anyone. The other books? Only to masochists.

    --

    These are my friends, See how they glisten. See this one shine, how he smiles in the light.
    1. Re:Hated it by holy+zarquon's+singi · · Score: 2, Informative

      I tend to concur, although Learning Perl Objects, References and Modules is a pretty good read and a good companion to the cookbook.

      --
      "...we should just trust our president in every decision that he makes and we should just support that." B.Spears 2003
    2. Re:Hated it by PCM2 · · Score: 2, Informative

      I sort of concur, though you have to start somewhere just to pick up the syntax of the language. For that, I used Programming Perl (the bigger, more reference-oriented book). Probably the most enlightening one I read was Advanced Perl Programming, which has also just been updated. That was the one that made me say, "Ah-haaaaaa, so there's more to this than CGI scripts."

      --
      Breakfast served all day!
  3. regex by __aahsof7392 · · Score: 3, Informative

    Example makes no sense.

    $ echo "I'm talking about the cartoon with Fred and Wilma!" | perl -pe 's#(.*)#$1#g;'
    I'm talking about the cartoon with Fred and Wilma!
    $ echo "I thought you said Fred and Velma, not Wilma" | perl -pe 's#(.*?)#$1#g;';
    I thought you said Fred and Velma, not Wilma

    1. Re:regex by slavemowgli · · Score: 2, Informative

      The author just forgot to escape some < and > characters in there, so part of the regexes gets interpreted as HTML.

      And of course, the Slashdot editors didn't catch that, but that's probably hardly surprising...

      --
      quidquid latine dictum sit altum videtur.
  4. Re:What's wrong with the example? by Yath · · Score: 4, Informative

    Since it says something about removing tags, I'd guess that the reviewer's angle brackets got removed by Slashcode. It's probably something like:

    s#<(.*)>#$1#g;

    Which is indeed a good example of a bad regex.

    --
    I always mod up spelling trolls.
  5. Re:Pattern by AuMatar · · Score: 3, Informative

    You can do it similarly in perl-

    \d{3}-\d{4}

    The reason perl implementations tend to look worse is that they try and catch other ways of writing phone numbers- removing the -, adding an area code, optional whitespace, etc.

    --
    I still have more fans than freaks. WTF is wrong with you people?
  6. The regex example as it should have displayed: by Craig+Maloney · · Score: 4, Informative

    Here's the text:
    I'm talking about the cartoon with Fred and <BOLD>Wilma</BOLD>!

    And here's a substitution to remove those tags. But what's wrong with it?

    s#<BOLD>(.*)</BOLD>#$1#g;

    The problem is that the star is greedy. What if the text had said this instead?

    I thought you said Fred and <BOLD>Velma</BOLD>, not <BOLD>Wilma</BOLD>

    In that case, the pattern would match from the first <BOLD> to the last </BOLD>, leaving intact the ones in the middle of the line. Oops! Instead, we want a non-greedy quantifier. The non-greedy form of star is *?, so the substitution now looks like this:

    s#<BOLD>(.*?)</BOLD>#$1#g;

    And it does the right thing.

  7. Re:Question by merlyn · · Score: 3, Informative

    We pitched this book to O'Reilly as "the last edition before Perl6 comes out". So, that's the scoop. One last chance to get Learning Perl for Perl5 correct. And apparently, we did the job.

  8. Re:PP 4th ed.? by merlyn · · Score: 2, Informative

    Camel 4ed will likely come out after Perl6. So Camel 3ed is likely the last Perl5 edition.

  9. Re:Cynical O'Reilly marketing exercise by merlyn · · Score: 3, Informative
    Actually, can I be honest?

    We didn't really have 5.8's differences in mind. However, we made sure that the exercises were not invalidated by 5.8.

    So yeah, you got us. It's a marketing ploy.

    However, we did do more than "rearrange" things. We're constantly updating our Llama class, and the latest changes were indeed dragged back into this book. So, you've got the best of an already good class, as updated by people that are teaching it every week.

  10. Re:I waiting for perl.NET to be released! by truckaxle · · Score: 2, Informative

    Why is this funny? I have sitting on my desk "Programming Perl in the .Net Environment" by Yevgeny Menaker, Michael Saltzman and Robert j. Oberg published by Printice Hall. The book is about 2 years old now.

  11. Re:I wouldn't buy anything from this author by Camel+Pilot · · Score: 4, Informative

    I just read the last 40 posts of one Mr Randal L. Schwartz on PerlMonks as per his link here and found none to be aggressive or unprofessional and instead helpful if not patient. Sorry AC you must have some axe to grind.