Posted
by
timothy
on Tuesday August 05, 2003 @01:15PM
from the taking-up-the-space-in-your-brain dept.

honestpuck writes "In the world of Perl there was once only the 'camel book,' held in perhaps as much reverence as 'K & R' among C programmers. It certainly appealed to roughly the same audience, those who wanted a short, sharp introduction to a programming language. It was with a problem that needed solving and a copy of the camel book that I started as a Perl programmer." Read on for honestpuck's review of another book he regards at least as highly.

Learning Perl Objects, References & Modules

author

Randal L. Schwartz with Tom Phoenix

pages

205

publisher

O'Reilly

rating

9.9 - Cannot find a fault

reviewer

Tony Williams

ISBN

0596004788

summary

Perfect book for taking your Perl skills to the next level

Then for those that wanted a introduction to Perl and programming Randal L. Schwartz wrote Learning Perl, a book that has arguably become the definitive textbook for teaching Perl. The one weakness was that it left off before really getting to the guts of building large, complex projects in Perl. It did not cover classes, objects, breaking your code up into pieces or the more arcane aspects of variables, references. For this we had to resort to the last few chapters of the 'camel book' and I, for one, have never really been totally comfortable at this end of the language; when I'm reading someone else's code it might take a couple of reads to fully understand the process.

Now this weakness has been well and truly addressed. Schwartz, with Tom Phoenix, has written "Learning Perl Objects, References & Modules", a volume that takes the same steady approach to teaching you the more advanced topics as the earlier 'Learning Perl'. Schwartz has spent the years since writing 'Learning Perl' teaching and writing. You can tell, this is a superbly written book, not that 'Learning Perl' wasn't well written; it's just that this volume is far better.

The Guts

The book starts with a chapter on building larger programs that covers @INC, eval, do and require before discussing packages and scope. It then has several chapters on references that explains in well understandable fashion and increasing complexity all the ins and outs of references including dereferencing, nested references, references to subroutines and references to anonymous data before a final chapter on references that gives you some incredibly useful tricks such as sorting and recursively defining complex data.

The book continues with three chapters that give you a solid grounding in Perl objects. Here Schwartz has assumed that you know at least a little about object oriented programming, some may feel the need for more explanation of concepts might be required, but if you've had any experience in OOP before then the clear examples and descriptions here are probably all you want.

Modules are not as well covered, with only a single chapter, but it is hard to think of anything left out, it covers using them and building your own so well that it left me wondering what all the fuss was about, "seems obvious to me." The book concludes with chapters on building a distribution out of your module, testing it using make test (with Test::Harness), Test::Simple and Test::More before a chapter telling you how to contribute to CPAN.

Each chapter of the book concludes with a number of small exercises, designed to be done in just a few minutes, that cement the learning of the previous chapter. The answers to these are at the end of the book.

Conclusion

Once I'd finished I felt I had a much more solid grounding in Perl, certainly I was much better able to understand another programmer's code that dealt with such things as subroutine references and some complex data structures. While the subject matter of this book is almost entirely covered in 'Programming Perl' the tutorial aspects of this book made it much easier going. The style would be familiar to anyone who has read 'Learning Perl', light without being frivolous and extremely well written, Schwartz seems a master at reducing complexity to manageable bites.

This book is deceptively easy to follow, each new idea built onto earlier ones, each new language concept introduced in an easy manner. The writing is excellent, it's hard to explain why I appreciated it so much. That may be the reason, the writing isn't forced or heavy or too light or obvious. It just allows the solid material of the book to shine through. Go to the ubiquitous O'Reilly website and grab the example chapter (the site also has a few Errata, the Table of Contents and the code from the book) and give it a look.

I think this may well become a classic, I may well in ten years time talk of Schwartz's books with the same awe I now talk of Brian Kernighan's. I'll certainly eagerly await his next book and keep this one close until it comes. Oh, and Randal, how about 'Software Tools for Perl Programmers'?

Actually, I disagree and think just the opposite. In many cases, I find that perl is easier to read because of all the "symbols" at the begining of variables and such.

For instance, in Java "String foo;" and in perl "$foo". Now, later in the code, if I see "$foo" in my perl code, I know immediatly that I'm dealing with a scalar, or %foo is a hash, whereas in most other languages I have to either remember the variable declarations or go back and find the variable declaration in the file.

Also, I think alot the supposed unreadability of perl has to do with regex. Since regex is such a basic part of perl, it gets used alot and when you come across "$_ =~ s/^([^ ]*) *([^ ]*)/$2 $1/;" you may attribute the mess of characters to perl when in fact, most of the mess is regex, which exists in many languages.

This is not to say that I haven't see lots of ugly code, perl or otherwise but I don't think perl is really any more difficult to read than other languages.

Oh no, I'm going to get moderated down, but
honestly, I don't mean this as a troll.

This got posted to a thread I was following
once:

/* * S_intuit_method * * Does all the checking to disambiguate * foo bar * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). * * First argument is the stuff after the first token, e.g. "bar". * * Not a method if bar is a filehandle. * Not a method if foo is a subroutine prototyped to take a f

That code is handling "indirect object" syntax, a syntax that was an interesting experiment but is all but extinct, after discovering that it can lead to some interesting problems. Unfortunately, for backward compatibility, that code still has to DWIM a bit to keep the legacy code working.

>Now, later in the code, if I see "$foo" in my perl code,>I know immediatly that I'm dealing with a scalar

And this could be any one of:- an integer- a real number- a string- a reference to an array- a reference to a blessed array- a reference to a hash- a reference to a blessed hash- a reference to a scalar- a reference to a blessed scalar

Well thank goodness that $ is there so that it's so easy to tell what type of data the variable holds.

Naming your variables is the clue here... I cannot event think of some code where I create a variable called foo.. name it afther its type, eg. sFoo for string, nFoo for int etc.. much more pleasing to read code. Same thing with classes and objects, classes = cFoo, objFoo for objects.. you get the clue.

The readability problem with Perl is a cultural one, not a language one. The language itself is very simple to read, with the possible exception of the more complex regular expressions.

The difficulty lies in the fact that it is possible to obfuscate Perl to such a degree, and that so many Perl hackers seem to think more obfuscation makes them look like a better programmer. There's even a contect that rewards this kind of thing.

If you want to write good, maintainable code, you can do it in Perl just as well as any other language. If you want to write an obfuscated mess, the same holds true. Sure, writing obfuscated Perl may make you feel more manly or whatever in the short term, but it won't help you keep your job when you can't read what you've written 6 months later.

I think you're right about confusing obfuscation with programming machismo. But I have to say that no regular expression I've ever seen (except perhaps for last page of Mastering Regular Expressions) has been as baffling as something like $foo{$bar}{$foo2}. For me references and dereferencing and dereferencing shortcuts are the least readable elements of perl.

But perl's mindset from what I can tell is power through brevity and flexibility. Going from it to Java is tortuous. So many words to type!!! But the

The C syntax is horrible, have you programmedin other languages in order to see the difference?I can think of at least 2 languages that are50 miles simpler to read.

But syntax is not a major issue anyway. Themain issue is the capabilities of the language.Apparently, those who speak on issues of syntaxand general look-and-feel have no knowledgeto talk about the more techincal issues. So herehere you have it: 1000 posts about how thelanguage "feels", and we are going to skipthe hard technical issues which yo

You imply that you make your living in programming andthat the "feel" of a language is important. Why?As a programmer you should know that the "feel"of the language is probably the least of yourworries. You know what other issues are important,but since you have to ask, and I don't feellike embarking on 3000 word essay, lets onlymention that the capabilities of the languageis more important than "feel", yes, and we are notfagots. W

I totally agree. There is *nothing* in the language that forces people to write bad code with Perl (and frankly there are plenty of unreadable non-Perl projects out there).

On the POPFile project I've done everything I can to avoid Perl's temptations into obscurity by writing clear code. Amazingly I've been critized by monoric readers of the code that I could have done things with less "space" (i.e. using less screen real estate). People like that know nothing about maintenance of code and should just bu

NOTE: I had actually written out a list of them here, and there are about 30 of them, but/. won't let me post it:"Lameness filter encountered. Post aborted!Reason: Please use fewer 'junk' characters."Which kinda makes my point in a roundabout way.

I mean, seriously. These are all valid variables in Perl and have specific meanings. But they aren't exactly readable. Some of them (like $| and $_) you probably already know, but the Perl brevity /

The readability problem with Perl is a cultural one, not a language one. The language itself is very simple to read, with the possible exception of the more complex regular expressions.

I totally agree with you. Even in the case of regexps, the/x modifier is available and you can use it to add spaces and even comments to enhance your code's readability. So again, it boils down to the programmer and his/her preferred style.

The difficulty lies in the fact that it is possible to obfuscate Perl to such a d

I seriously believe being a perl programmer is a little like being a smoker: After smoking a while you don't remember why you started anymore. All you know is that it's easier to continue than to break the habit. That's the case for me, anyway.

I haven't read this book, but I'm fascinated by the moderation of the parent comment as "insightful"..."informative", perhaps... after all, it does confirm that the light nature of the writing style will turn off those who prefer dense technical writing... but it does so in a shallow manner that sheds no light on why such a writing style might be a bad thing. If anything, this post represents the opposite of insightful thinking.

"covered" is not "lifted... verbatim". If you can't tell the difference between tutorials and reference material, you're not qualified to make the comment you've made. You still haven't shown any part of PP that was "lifted" to make LP. Put up or shut up.

This is so far from K&R it's sacrelige to even make the comparison. Shame on you.

Um, the reviewer was comparing K&R to "Programming Perl" -- a/k/a "The Camel Book" -- not to the book being reviewed. Which is a fair comparison in that both books pretty much define the language in question.

You dont have to read the book, or even know what it's about. Look for a post I made in this thread that got +5 Insightful. I've never read this book and I dont use Perl. Just string together a bunch of "kudos" or "boos" and toss in a couple buzzwords (K&R works fine), and there you go.

And that makes his opinion irrelevant just how? I assume your comment implies that the post above should have been moderated down instead of up. Why? Because of his posting history?

"Stratjakt is a known Communist. Check out his other work."

You are suffering from the Dubyaitis: everything's black and white, good and evil, trolling and "serious" slashdot use. The world doesn't work like that, my friend. The world is not black and white. The world is shades of gray.

That book is essentially worthless except for looking up random facts after you've been programming C for a few months. In contrast, the camel book is useful even for long-time Perl hackers, because Perl has more built into the language (e.g., regexps, hashes, etc.) than C, the latter of which is incredibly simple by comparison.

[Aside: The book I use most often is Stroustrup's C++ Second Edition, which in itself is rather vague and outdated wrt the details I need to know most often these days. I'm thinking of getting myself a copy of one of the C++ specs to help me answer the really obscure questions. Does someone recommend a particular spec (e.g., ANSI, ISO)?]

That book is essentially worthless except for looking up random facts after you've been programming C for a few months.

I couldn't disagree more. I learned C from the original K&R book. It was well organized, clear, and consise. The Camel book, on the other hand, often seemed like concepts on page n relied on concepts introduced on page n+1. I found that no matter how much I programmed in Perl (about a year's worth of time) and no matter how much I used the Camel book, I could never find what I was looking for without a massive search.

This is why I laughed at the original post -- if the Camel book is a "short, sharp introduction," I'd hate to see the reviewer's idea of a sprawling book.

To be fair, a sprawling language like Perl needs a sprawling reference, and the Camel book does a decent job of it.

Personally, I don't often refer to K&R, but that's because C is a simple language that you can learn in its entirety without too much effort. Who truly knows all of Perl? Or C++ or COBOL, to mention two other giant languages? A small per

I'm thinking of getting myself a copy of one of the C++ specs to help me answer the really obscure questions. Does someone recommend a particular spec (e.g., ANSI, ISO)?

Actually, this [sun.com] pretty much solved all my obscure or arcane C++ questions. In fact, while referring to that I haven't once had trouble figuring out if I was implicitly causing a conversion which caused a deep copy which in turn caused a memory leak since.

Of course, "Why did my program just pause for a 1/10th of a second, and how can I avoid that?" comes up more often now.

It took me a second to get the joke, but your point is well taken. I have taken great pains to implement garbage collection in C++, but significant understanding of the language is still required to avoid certain pessimal behaviors, which is especially problematic when others use my garbage collector.:)

So much of this stuff is in the perldocs. I applaud O'Reilly for supporting open source but outside of the Camel book and the Perl Cookbook, I think the rest of the books are mostly redundant.

At some point you have to put the books down and start programming if you truly want to master the language. After the Camel book is probably a good time to start, with references to the Cookbook when needed. For other info, the perldocs are recommended.

The camel book is pretty much entirely in perldocs as well. In fact, most of it is verbatim.

Having said that, the Camel book is probably the single most useful programming book I have ever read. I bought my copy 6 or so years ago (right after the 2nd edition came out) and I still use it to this day. It is unusual in that it not only allows one to pick up the language quickly and easily, but is concise enough to be used as a quick reference that is often more handy than the perldocs.

It may be that I had already been programming Perl for too long before the other books came out, but I was never able to find anything really useful at all from them.

I can't say I fully agree with that. While the book may seem redundant for the experienced perl programmer, I just finished it and would definately say it fits it's target market. I know a bunch of developers who started with the llama, went to the camel, but lost out on the good info that this puts inbetween. Some kinda Oreo Cream filling between the llama and camel.

I would definately recommend this book to the developers who are at that stage of their development. It's a useful tutorial style book for

How bout "has anyone started both books?" Based on that comparison I'd say I've gotten farther in this book than I ever did in Damian Conway's book (which I had really high expectations for based on reviews). In fact I think I started the Conway book more than once but never got more than 1/4 of the way through it. I'm halfway through this one now and have no doubts that I'll complete it.

Of course then I might go back and reread the Conway just to see if it makes more sense.

I've read it cover to cover and use it frequently. Definitely the best perl book I've read (with the list of "perl books I've read" consisting of most of the O'Reilly line).
Conway covers OOP theory, how to apply it in perl, neat perl-only tricks, and a lot of fun stuff. His examples are hilarious and his writing among the best traditions of technical instruction.
Even OOP aside, I learned more about perl from Damian's book than anything else I've read. Highly recommended.

Conway's book is the best I've read on the subject of perl OOP. If you take the time to make sure you *understand* each and every concept and mechanism, the book will leave you with a firm understanding of objects. This shouldn't be a problem as the book is a delightful read. A firm understanding of the perl language, references, globs, packages, etc would be an important requisite as the book is not for the novice.

I started Damiens book, and it was way to dense for me. I just picked up Randals book and started it last night. It truly starts where learning perl (and the coookbook) ends and I feel that I'll be much more successdful understanding this book (and hence, becoming an OO perl programmer).

I'm not bagging on Damiens book at all - it just started above my head.

As for the poeple baggin on Randals book, my guess is is started at too low a level for them, so they think its useless - completly forgetting that t

Damian's book is great, but a good comparison would be that Learning Perl is to the Camel what Learning Perl Objects, References and Modules is to Damian's book. Both of my tutorial books are tutorial in design, based on years of classroom experience in teaching these subjects. Both of the other books are reference in design.

Also, the OO part of the Alpaca book is only a portion of the text, and is necessarily light in coverage. The point of the Alpaca is to get you to understand most 100 to 10,000 lin

Damian's book is great, but a good comparison would be that Learning Perl is to the Camel what Learning Perl Objects, References and Modules is to Damian's book. Both of my tutorial books are tutorial in design, based on years of classroom experience in teaching these subjects. Both of the other books are reference in design.

Hi, Randal,

The Gecko book was very important to me when I made the big step from Perl as a replacement for awk scripts to Perl as an application development tool, around 1997 (the

The Jaguar book is dated. It filled a nice niche at the time, but the world progressed beyond it rather quickly. It describes a deprecated XS interface, an obsolete module packaging scheme, and objects before we really understood everything that was going on in Larry's head.

It's still selling because it still sells. O'Reilly doesn't drop books that still make a profit, even when they're outdated.

I'd consider the Alpaca plus Damian's book to be a complete replacement of everything that the Jaguar had

I second most of the positive comments here about Damian Conway's book.

Just want to add that even after using perl for a few years, his beginning 1/3 chapters alone are worth the price of the book. It's a refresher on the fundamentals of perl, with good, funny examples of just about 90% of everything I knew. Even lots that I *didn't* know, with me going "Wow, I didn't know you can do that!". Heck, most of the important stuff from the Camel book is summarised here.

Some people need books, others don't. Personally I find the ActivePerl documentation to be excellent.

The idea that you can do a PPM search for a module via CPAN based on your need, download it, and have it's docs integrated into the centralized documentation is great. perlfunc, perlre, perlobj, etc are a bit arcane but with a little elbow grease and a good editor (SlickEdit!), you figure things out pretty quick.

BUTTTTTTTTTTTTTTTTTTTTTTTTTT, just before I read your post demanding that it be knocked down I was thinking that someone should start a new subject on "Learning programming through books - pros and cons" or some such thing. I keep noticing these statements from people who claim that they don't need to read books, and seem to be proud of it. Personally I think that's nuts. But there certainly do seem to be a number of people of that persuasion. Much of it seems

I think the books vs no-books is based in part on age, but only because age relates to school, which is book oriented. Those who have been out of school a while, or never went to college, may find through experience that skipping books and going straight for built-in docs (or trial and error) works for them.

Younger folks tend to prefer books especially if they just finished, or are still in, college, for obvious reasons.

I think there's more to books than "need". I don't need technical books in most cases, because of the extensive information available online. This is especially true of perl, whose documentation is unbelievably vast. But I *like* books (as opposed to need). They're nice to have on the shelf and in a comfortable chair. It gets me the heck of the computer from time to time to read some thoughtful insight from somebody more experienced than me, and to read text that didn't have to be antialiased:)

I recently bought this, and for much the same reasons as the reviewer.

Basically, if your introduction to Perl was via "Learning Perl" then this is probably a great next step. I went through the Camel book and the Perl cookbook instead, and find that this one does not give all that much more information as I would have liked. This is not strange; the authors explicitly say in the preface that this is the companion book to "Learning Perl".

On the upside, it does give a good deal of useful snippets of info, and it manages to give clear explanations for some stuff that is otherwise quite opaque; the way it explains the Perl object model, for example is much clearer to me than the treatment given in the Camel book.

I would have given it 7.5-8 rather than the extreme score the reviewer gave.

and it's slow going, but I've sure learned a lot. Now maybe I'm dense but I don't think that references, anonymous hashes, references, subroutines are all that easily understood. In fact you can accomplish a whole hell of a lot in Perl without understanding them. But for anyone wanting to make the jump to larger more complex programs you really need to understand them. I'm just finishing the references section (first half) and still have the objects section ahead of me. I've read the tutorial on objects before and at first glance this book looks similar to it. But I didn't get as far in the tutorial as I would have liked, I think because I didn't understand references as well as I should. With the solid foundation that this book gives I think that I'll get a whole lot more out of the objects section, even if it more or less duplicates the tutorial (which I doubt).

So, half way through, I give it two thumbs up. My Perl programming has just gotten a lot more sophisticated. Maybe I was dense to begin with but any step up is something I'm happy about.

As far as those nutty complaints about O'Reilly lingering at the bottom of this thread all I can say is that they've found their proper place.

I wouldn't recommend it to anybody. The way it makes you put different objects in different files/modules is so counter to Perl's scripting heritage that a good procedural/reusability-based outlook will get a lot more traction than this OO mess, at least 'til Perl 6.

The way it makes you put different objects in different files/modules is so counter to Perl's scripting heritage

Different classes can be defined in the same file, no problem - just make a package declaration to begin each new one.

Having said that, I've never wanted to actually have more than one class in a file. Sure, OO is counter to 'Perl's scripting heritage', but so what? There's a reason that much of the good stuff on CPAN is written in an OO style.

How does honestpuck have teh time to review so many terse technical books? I wonder if these reviews are as well thought out as they could be if honestpuck was not trying to crank out 3 a week. I am going to propose the conspiracty theory that honestpuck is really an alias for a group of 10 Slash developers!

You dont have to read the book, or even know what it's about. Look for a post I made in this thread that got +5 Insightful. I've never read this book and I dont use Perl. Just string together a bunch of "kudos" or "boos" and toss in a couple buzzwords (K&R works fine), and there you go.

While it sometimes seems as if I'm paying the grocery bills for 10 people, no, there's only one of me.

Actually, the last three reviews published here were written over about 6 to 8 weeks and submitted to Slashdot over a 5 week period. The books were read over an even longer period, it's just that I often write reviews in a surge of two or three at a time. I'm also usually writing a couple of reviews at once as I always re-read a book after a first draft of the review.

Randal Schwartz is a regular over at PerlMonks.org. He's replied to a couple of my threads and helped me out of some sticky situations. It's rare for such a talented programmer to be so accessible and helpful to the public.

... because very few perl scripters know how to do it... write an OOP script in Perl, and only an expert will be able to maintain your work.

This is so common in Perl (and other languages). Especially with contractors, for some reason. They come in, write expert level code, using all the secret codes and handshakes, then the average schmucks in the cube farms cannot maintain the code.

Wouldn't that be the fault of the people who didn't bother to learn basic concepts like OO programming rather than the fault of the people who know how to use it?

OO in Perl is not hard, sure its syntax is a bit different but the concepts are the same and there are multiple books (like this one), online resources such as this [perlmonks.org], and not to mention the existance of 4 (not 1 or 2 but 4) tutorials on OO in perl that come with the documentation. If people don't expect their "schmucks in the cube farm" to be skilled in a language then its no wonder that our jobs are going to India!

And there are reasons there are 4 documents about it. OOP shouldn't be as hard as Perl makes it out to be.
Personally I try to pretend Perl doesn't have objects and even references, because trying to use the things is a complete nightmare. This is also the point you should switch to something better designed for the task - such as Python.
ISn't @ISA the biggest hack possible??

I'll concede that OO could be done better (and yes I do like Python) but if you don't understand refs then don't program Perl because refs are extremely useful things, how are they any harder than pointers in C?

Almost every perl programmer will spout on and on about how great the Camel book is when in fact, as technical books go, it sucks. Witty, eccentric examples don't make a great book. The fact is no one wants to admit that the book sucks because they will be thought of as a fool. So they proudly trumpet from the mountain tops that nothing is better than the camel book all the while hoping no one notices that they don't understand a bit of it.

Great book and a must-have if you enjoyed "Learning Perl" and would like to round out your knowledge of the language. Daimon Conway's "Object-Oriented Perl" is also a great book and would follow nicely from Randal's if your objective is to write good OO code in Perl.

Even though I already have Conway's book I still picked up Schwartz's since I need a quick refresher and Schwartz has a knack for being clear, concise and congenial for the real-world programmer.

It certainly appealed to roughly the same audience, those who wanted a short, sharp introduction to a programming language.

I like the Camel Book, but short it ain't. The Third Edition is 1067 pages. For that much paper you can have K&R2 and Advanced Programming in the UNIX Environment, or the ISO C spec and a pretty complete POSIX reference, or almost half of the GCC manpage.