The Perl Cookbook, 2nd Edition 148
The Perl Cookbook, 2nd Edition | |
author | Tom Christiansen & Nathan Torkington |
pages | 927 |
publisher | O' Reilly |
rating | 9 |
reviewer | doom |
ISBN | 0596003137 |
summary | How to do common tasks in perl |
The new recipes cover a number of subjects. One of the prominent themes is how to use perl's new unicode support, as well as the new I/O layers feature. The coverage of web programming has definitely been fleshed out with recipes on XML-RPC, SOAP and so on, plus the new chapter on mod_perl. Also of interest of course are the additional recipes on database access with DBI.
The mod_perl chapter is a good succinct introduction, with some very cute recipes in it (though admittedly a lot of these are also covered in the excellent Mod_perl Developer's Cookbook by Young, Lindner and Kobes out from Sams). For example "Transparently Storing Information in URLs" shows how to embed information in any arbitrary position inside a URL. This quickly shows the kind of things you can do with a PerlTransHandler and a PerlFixupHandler. The chapter closes with what looks like a good introduction to "Template Toolkit", which I would probably be very excited about if I wasn't already familiar with the (also discussed) HTML::Mason.
I really enjoyed reading the XML chapter (a subject I'm less familiar with): I predict that you'll find this to be the fastest way through the XALPHABET XSOUP without drowning. For me, this was almost worth the price of the book.
Very little has been removed (hence the page count has gone from 757 to 927), and where I have been able to find a deletion, there are usually very good reasons for it. For example, the first edition takes the trouble to tell us that qr// was introduced in perl 5.005, but the new edition drops the babble about versions there, because for most of us, anything before 5.6 is now ancient history. However, I do miss this particular irrelevant parenthetic aside that's been deleted now:
(p.295, first edition, compare to p.323, second edition.)Remember that the opposite ofread is not write but print, although oddly enough, the opposite of sysread actually is syswrite. (split and join are opposites, but there's no speak to match listen, no resurrect for kill, and no curse for bless.)
In general, it's difficult to think of anything seriously wrong with the Perl Cookbook. I might suggest that in some places they fall into the trap of talking about all the ways to do it, rather than just the best ways, (e.g. recipe 7.5 "Storing Filehandles into Variables" seems a bit complicated).
And maybe there are some slight problems with order of presentation, as with the new perl 5.8 feature of "I/O Layers", which is mentioned a few times before it's finally discussed in the beginning of Chapter 8 (though really, it's amazing that there aren't more problems like this: this is supposed to be reference work, and yet it usually works well as a tutorial also).
I've got one big complaint about the 2nd edition though: they changed the numbering of existing recipes! I've been writing code with comments like
and now it turns out I should've been specifying an edition number also. Please: "Cookbook" authors, come up with a numbering scheme that remains invariant with new editions... if you can't always just append to the end of the chapter, there's nothing wrong with tacking another dotted decimal on the end. We're programmers, we can handle it.# Schwartzian transform. See Perl Cookbook, recipe 4.15
And speaking of the "Schwartzian transform" that recipe has a very clear, self-explanatory name "Sorting a List by Computable Field", but in the first edition, there was also a footnote explaining that many people call this the Schwartzian Transform, named after Randall Schwartz, who invented the technique. With this second edition, that footnote has been quietly dropped. Guys, if you're going to carry on a feud, this is really not the way to do it. It just makes you look bad.
O'Reilly's perl.com site has a series of articles by the authors, featuring some recipes from the book:
Appendix: New recipes and examples (not including the two new chapters):
- Using Named Unicode Characters
- Treating Unicode Combined Characters as Single Characters
- Canonicalizing Strings with Unicode Combined Characters
- Treating a Unicode String as Octets
- Properly Capitalizing a Title or Headline
- Constant Variables
- Implementing a Sparse Array
- Creating a Hash with Immutable Keys or Values
- Matching Nested Patterns
- Writing a Subroutine That Takes Filehandles as Built-ins Do
- Storing Multiple Files in the DATA Area
- Reading an Entire Line Without Blocking
- Treating a File as an Array
- Setting the Default I/O Layers
- Reading or Writing Unicode from a Filehandle
- Converting Microsoft Text Files into Unicode
- Comparing the Contents of Two Files
- Pretending a String Is a File
- Working with Symbolic File Permissions Instead of Octal Values
- Writing a Switch Statement
- Coping with Circular Data Structures Using Weak References
- Program: Outlines
- Overriding a Built-in Function in All Packages
- Customizing Warnings
- Writing Extensions in C with Inline::C
- Cloning Constructors
- Copy Constructors
- Saving Query Results to Excel or CSV
- Escaping Quotes
- Dealing with Database Errors
- Repeating Queries Efficiently
- Building Queries Programmatically
- Finding the Number of Rows Returned by a Query
- Using Transactions
- Viewing Data One Page at a Time
- Querying a CSV File with SQL
- Using SQL Without a Database Server
- Graphing Data
- Thumbnailing Images
- Adding Text to an Image
- Program: graphbox
- Turning Signals into Fatal Errors
- Multitasking Server with Threads
- Writing a Multitasking Server with POE
- Accessing an LDAP Server
- Sending Attachments in Mail
- Extracting Attachments from Mail
- Writing an XML-RPC Server
- Writing an XML-RPC Client
- Writing a SOAP Server
- Writing a SOAP Client
- Program: rfrm
- Using Cookies
- Fetching Password-Protected Pages
- Fetching https:// Web Pages
- Resuming an HTTP GET
- Parsing HTML
- Extracting Table Data
You can purchase The Perl Cookbook, 2nd 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.
same price and free shipping (Score:1, Informative)
Bookpool has it for 30 bucks (Score:1)
-B
Re:Bookpool has it for 30 bucks (Score:1)
Doesn't work for Perl 6 though... (Score:4, Informative)
O'Reilly addresses the issue here [oreilly.com]
Still Perl is such a beautiful thing you should buy ALL Perl books.
Re:Doesn't work for Perl 6 though... (Score:1)
Re:Doesn't work for Perl 6 though... (Score:1)
But the bookshelf can't take any more! Seriously speaking, my O'Reilly shelf is packed, 15 volumes at work (not just Perl), and I think I have more stashed at home.
Makes me wonder though if anyone out there has a huge O'Reilly collection. Or does everyone migrate to CDs...
15? (Score:2)
Re:Doesn't work for Perl 6 though... (Score:2)
Still Perl is such a beautiful thing you should buy ALL O'Reilley Perl books.
The O'reilley books are excellent. They are written by some of the major coders for perl like Larry Wall, Tom Christiansen, and David Swartz (I think thats his name).
They are informative and fun to read because of the humor and relevant info that are in the books. I have a copy of the 1st edition of the Perl Cookbook, and it is probably my favorite programming book that I own, and I would imagine that I'll be gett
Re:Doesn't work for Perl 6 though... (Score:1)
but you have already said that the name was
probably incorrect.
Re:Doesn't work for Perl 6 though... (Score:1)
What you say is true for Perl 6 the language, but not perl 6 the interpreter.
My understanding is that the perl 6 interpreter, despite being a ground-up rewrite, will run Perl 5.x scripts perfectly well.
From what I can gather, the perl6 interpreter will consist of a sort of 'meta-interpreter' (Parrot), plus modules that tell it how to interpret a particular language. The interpreter will automatically detect which language (and which variant of the language) you are trying to use. So you could, in princi
But.. (Score:1, Troll)
Rus
Re:But.. (Score:1)
I call troll (Score:2)
The whole thing is an exercise in pseudo-computer science masturbation
You talk about it as if Perl operates on mysterious brand-new concepts. It's a pragmatic language. None of it is particularly unique to Perl. In fact, if you search Google for 'pragmatic programming' the Googl
Re:Perl6 is a mistake (Score:1)
Perl6 is a mistake (Score:0, Flamebait)
Re:Perl6 is a mistake (Score:1)
How do you test Unicode? (Score:5, Interesting)
Re:How do you test Unicode? (Score:2)
Re:My problem with Perl (Score:4, Insightful)
After a little hands-on work, you'll start to understand the logic behind all the line noise, and once you get to that point, the pure beauty of regexes and what they can do becomes clear.
In a way, it's a little bit like learning to program assembler. At first, all those opcodes are just a confusing mess, but once you get the hang of it, it starts to become clear.
DG
Re:My problem with Perl (Score:1)
It's funny how many people will bitch about regular expressions, but only a very few people bitch about something much uglier like XPath. Maybe it's just that not too many people have been exposed to XPath to complain about it yet.
Re:My problem with Perl (Score:1)
Re:My problem with Perl (Score:1)
Re:My problem with Perl (Score:1)
You mentioned you're a physicist -- how do you remember all those rules and formulas? The same principle applies. Writing regular expressions isn't complicated. It just takes time to learn well, like anything else. And "learning stuff by heart" is just rote memorization -- even animals can do that.
-toomuchPerl
Re:My problem with Perl (Score:3, Insightful)
It's true that people writing in Perl tend to use regular expressions in places where they're not necessarily appropriate. For instance, algorithmically speaking, subsequence matches are faster than regular-expression matches. (This is why Python has the .startswith and .endswith string methods, and the in operator.) However, the Perl regular-expression engine (PCRE) is optimized to heck and its raw speed can usually overcome this.
T
Re:My problem with Perl (Score:2)
Dude, I realize your post is about knocking perl regexes, but there's no need to obfuscate what could just as easily have been written as:
foo|bar|b(a|uz)z
or, even more simply, as
foo|buzz|ba[rz]
if you did not want to capture the a|uz, since you didn't indicate that you wanted to do so in your Lisp expression. Your eyes can pick that last one up in one chunk, and there's no need to scan back and forth t
Re:My problem with Perl (Score:1)
Actually, it wasn't. It was a discussion of the ways people use regex in Perl, and of the only other regex notation I'm familiar with besides Perl's.
Did you know that there are thousands of people in the world who discuss all manner of differemces without "knocking" anything? For instance, when biologists who study insects meet biologists who study lizards, they do not rant at one another about whether lizards r0x0r and insects sux0r or vice ver
Re:My problem with Perl (Score:2)
I think your reply is a bit of an over-reaction. Never did I say you ranted, and there's no call to become condescending. "Knock" is a pretty mild term for criticism. I don't think it's out of line to sa
Re:My problem with Perl (Score:2)
I don't do lisp, so
Re:My problem with Perl (Score:2)
Sounds like Regexp::English [cpan.org], only less explicit.
Re:Looks are deceiving. (Score:2)
Re:My problem with Perl (Score:1)
Re:My problem with Perl (Score:1)
I just don't have any projects!
I want to learn perl, but writing up half-hearted mock scripts doesn't teach you the same way as using it (or any language, package, device) to fulfill a certain need.
I'm also concerned about having to re-learn perl all over again when Perl6 is released.
Re:My problem with Perl (Score:2)
Of course, in that case you alse need Mastering Perl/Tk
Re:My problem with Perl (Score:1)
Re:My problem with Perl (Score:1)
/nova20
Re:My problem with Perl (Score:2)
Re:My problem with Perl (Score:1)
Even Larry wants you to use a dozen different methods to perform a single task.
Re:My problem with Perl (Score:1)
noise (and not even on the same line). Does that mean it will be better to
use instead English-like symbols? No. Most
chemists and mathematicians would prefer
to use what they already have. They only ones
who actually complain are those who are just
started learning Physics, Mathematics, or Chemistry.
How do you remember all these symbols, is the
same how you remember all these words in the
English language. You learn them!
Re:My problem with Perl (Score:2)
Silly Gripe? (Score:1)
Why not do this in the first place? Anyone who's written a university essay knows the importance of edition numbers. Page-numbering is particularly vulnerable, since even small clarifications will shift things around.
A different, and likely just as effecitive alternative, is to not specify the recipe number at all. Surely there's an index where you could look up "Schwartzian transform" without hard-coding the number.
Perl is like sex (Score:4, Funny)
Re:Perl is like sex (Score:1)
THERE IS MORE THAN ONE WAY TO DO IT!
Re:Perl is like sex (Score:2)
Re:Perl is like sex (Score:2)
It can get messy
If you aren't careful, you end up with a little monster you wish you had aborted before it got too big
Re:Perl is like sex (Score:2)
On the other hand, also like sex, it won't take as many years to get really good if you do bother to read some well-written books on the subject. Perl books tend not to have as many pictures, though.
Re:Perl is like sex (Score:2)
This is the Fucking Manual, everybody tells you to read when you ask stupid questions.
Re:Perl is like sex (Score:1)
And the most enjoyable similarity: If you get curious, you can always try it in private with a trusted partner! (Uh, does the computer count as a partner?)
Re:Perl is like sex (Score:2)
It isn't easy to get started, and most people only do enough to get finished quickly.
Even if you are extremely careful you'll probably end up with a big mess.
If you look at Perl long enough, you wish you'd done it with something else.
You and your partner are fantasizing about better equipment (Python) and/or gemstones (Ruby).
It can be constantly interrupted by poorly constructed arguments and (de)referencing past mistakes
It doesn't scale well beyond two developers.
perldoc.com (Score:2, Informative)
safari? (Score:1)
I haven't looked to see if this new one is on there yet - I have the old version of it in paperback form as I do with pretty much all the other O'Reilly Perl books.
Errors? (Score:1)
Correct me if I am wrong but I seem to remember that the first edition had quite a few errors (both syntactic and semantic). I'm guessing that the second edition has cleared all these up. However, when I try to access the errata for the first edition I can't find it! Surely support for previous editions doesn't "end" upon publication of
Re:Errors? (Score:1)
I agree with another post. PHP, Python, and other ways to go
Re:Errors? (Score:2)
PHP is the driving force behind mod_perl. It's great for small to medium stuff but I'd hate to write something big in PHP. (At least, where the guts are in the PHP - if it was only for templating it would be okay.)
Know the index... (Score:2, Informative)
It's unique in that it doesn't just tell you about specific language properties. It actually gives a problem, a solution, and an explanation.
Happy Day (Score:2)
Regardless of the religious wars over languages, I have time and again found Perl to simply be the most practical language for the job and continue to enjoy using it for a variety of tasks and watching it mature.
There is no substitute for the CPAN [cpan.org] or Perl's ability to get the job done quickly and easily with an active communit [perlmonks.org]
Schwartzian Transform (Score:4, Informative)
But I guess it's convenient to think of everything that happens as being the result of a feud and ignore inconvenient facts like the "Schwartzian Transform" name still being mentioned in the long entry on sort function in Programming Perl, 3ed, which Tom also cowrote. Hmm, maybe I shouldn't point that out--now I'll be accused of having a feud with Randal!
--Nat
Re:Schwartzian Transform (Score:2)
Re:Schwartzian Transform (Score:2)
Tom would want to rewrite history, making you believe that it was Larry's book, and that he asked me to co-author for some unjustifiable reason. That's clearly not the case. Check the facts first, please.
Re:Schwartzian Transform (Score:1, Flamebait)
As for this:
I would completely disagree. I challenge anyone to bring forward anything for which I'm not willing to take public responsibility.XML Chapter (Score:3, Interesting)
As you would have guessed if you heard me speak in 2000 [frii.com], I'm not the biggest XML user. I've mellowed since then, but I still don't do a lot of XML hacking. (One of the spare-time hacking things I've while here at O'Reilly, though, is to get our internal database of "what books are at what stage" into XML for easy grepping and reuse).
Of all my work in the 2nd edition of the Cookbook, the XML chapter is the one I'm proudest of. I'm really glad you like it. Thanks!
--Nat
Re:XML Chapter (Score:2)
Don't buy it (Score:1)
It has among others a very handy reference to Perl's built-in functions, lots of regexp stuff and more.
For everything else there is www.
Christiansen on /. (Score:1, Offtopic)
IIRC, then came karma.
Re:Christiansen on /. (Score:1, Offtopic)
Re:Christiansen on /. (Score:1, Offtopic)
Actually, I'm always a little amazed that any "big names" show up here, and then I'm amazed that I find that amazing.
Feh, I wish I had gotten my username here when I started reating, instead of a year or two after. I'd have an
Re:Christiansen on /. (Score:1)
A long time ago,
Before my time... (Score:2, Offtopic)
Perl CD Bookshelf - 4th edition (Score:1)
die if (perl_cookbook == 'poop') (Score:1)
Back in the day the venerable "Perl 5 HOWTO" was the shizzy for doing stuff before there was a billion modules in CPAN to do pretty much everything. I still refer to it when I need to write a server from scratch, even though its probably five years out of date now.
To the
Not entirely thorough (Score:1)
Sure, Laziness is a virtue and all that, but to cite a specific example, I looked up how to parse program options. All Cookbook has to say on the matter is to use GetOpt. This is fine, and is decent advice, until you realize that GetOpt is by no means a complete solution, as it doesn'
a feud would be double-sided (Score:1, Offtopic)
Re:Perl and Python... (Score:1)
Re:Perl and Python... (Score:2)
On the other hand, I'll admit that I never learned Perl because everything that I needed to implement could, indeed, be done with awk and sed--they are quite powerful for text proc
Re:Perl and Python... (Score:2)
That would be the Perl Power Tools project [perl.com].
Re:Perl and Python... (Score:2)
- doug
Re:Perl and Python... (Score:2)
Enjoy! [geht.net]
Re:Perl and Python... (Score:2)
Re:Perl and Python... (Score:2)
Re:Perl and Python... (Score:2)
Implementing FTP in awk (Score:2)
Jurgen Kahrs implemented socket IO in GNU awk around 1997. See Robbins' O'Reilly book "Effective Awk Programming" for more details, it's a great book (even though I think the name is lousy).
If the number of FTP commands you wanted to implement is K, I'd guesstimate you'd need about 30 + (K*2) lines of Gawk to implement a reasonably bulletproof FTP.
Gawk ships with most linux distros, but many of them are shipping outdated versions.
Re:Perl and Python... (Score:2)
I've (un)successfully used this to avoid learning both perl and python for some years. D'oh!
--
Ummm... (Score:1)