Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Wicked Cool Perl Scripts 239

Michael J. Ross writes "Of all the popular programming languages now in use, Perl is perhaps the best suited for writing utilities — for several reasons, such as its text-processing capabilities, ease of addressing system resources, and minimal language overhead for input, output, list processing. It was designed to blend the rapid solution development of shell scripting with the powerful control constructs of third-generation languages. Consequently, Perl quickly became a favorite language for developing programs ranging from system administration utilities to CGI scripts that power Web sites. In fact, Perl has been called the glue that holds the Internet together. The tremendous flexibility and power of Perl is seen in Steve Oualline's book Wicked Cool Perl Scripts: Useful Perl Scripts That Solve Difficult Problems." Read the rest of Michael's review
Wicked Cool Perl Scripts
author Steve Oualline
pages 336
publisher No Starch Press
rating 8
reviewer Michael J. Ross
ISBN 1593270623
summary 47 useful Perl scripts for Web site management or CGI, Linux or Unix system administration, managing pictures, etc.


Published by the cleverly named No Starch Press, Wicked Cool Perl Scripts comprises 336 pages, spanning 11 chapters, with a brief introduction, as well as an index. The book appeared in February 2006, and was published under the ISBN of 1593270623. No Starch Press maintains a Web page for the book, where readers can find a sample chapter (the third one, covering CGI debugging), in PDF format. There is a link for downloading all of the source code.

The book presents 47 scripts, grouped into 11 categories: general-purpose utilities, Web site management, CGI debugging, CGI programs, Internet data mining, Unix system administration, picture utilities, games and learning tools, development tools, mapping, and regular expression graphing. The scripts perform such functions as finding duplicate files on your PC, converting currencies, processing error logs, generating jokes randomly, getting stock quotes, and managing photos and other images. Some of the scripts play games, while others would be invaluable to any Linux or Unix system administrator. For readers with their own Web sites, the book offers scripts for verifying links, locating orphan files, detecting hackers, and locking them out. In addition, there is a script for counting the number of visitors to your site, and even one for presenting a guest book. Software developers will find the material valuable, as there are Perl scripts for generating code, locating dead code, and handling regular expressions — parsing and graphing them.

The scripts themselves are fairly wide ranging in complexity and size, with a few fitting on a single page of the book, while others require more than ten pages. Fortunately, the scripts generally contain enough comments to be clear in how they work to any programmer comfortable with the language. Nonetheless, the author explains how to run each script, what sort of results the reader should see, how the script works, and what modifications one might want to make to it ("hacking the script"). In addition, every one of the scripts contains a POD (Plain Old Documentation) section, though only in the downloadable version — not the version seen in the book, to save space.

It is doubtful that any beginning Perl programmer might mistake this book for a Perl primer or reference. The title alone makes clear that the focus is on the offered scripts themselves, and their ability to help the reader solve common problems. On the other hand, Perl programmers of any level of fluency with the language would benefit from reading through the scripts, as well as the author's explanation of how they address and solve each problem. I myself have been programming in Perl for ages, and yet I spotted CPAN modules that I can use in my own Perl scripts in the future.

The value of the scripts themselves to each individual reader, naturally depends upon what sort of tasks the reader would like to accomplish with Perl. The 11 categories of scripts are varied enough so as likely to be of use to just about anyone who would like to use the "Swiss Army knife of languages" for getting the job done on their computer, or that of their employer (as a system administrator). Personally I found most useful the scripts for detecting changed files, scanning Web sites for dead links, and parsing regular expressions.

There are other aspects to like about this book. It has a RepKover binding, to lay flat when open. The illustrations are clear and not excessive in number. Unlike some technical authors, whose weak attempts at humor simply make their obtuse material more annoying, Oualline is more subtle, such as his reference to the cost of Microsoft Windows CDs in a Hong Kong shop, or "Ingesting a Cheerio nasally." Well, perhaps not always subtle, but invariably welcome in what could otherwise be an extremely dry subject.

Like any book, there are some areas for improvement, perhaps in future editions: In the illustrations that employ rays pointing from one node to the next, some of the curved rays are remarkably jagged, as if they were not computer-generated. Far more importantly, some of the scripts could benefit from more internal comments, as well as having the code broken up into smaller functions, which improves clarity and maintainability. Also, some of the variables and functions could use more descriptive names. For instance, using two examples from a randomly chosen page: $file_name would be more clear than $cur_file (is it the file's name, full path, or contents?). print_file_cell() would be better than do_file() (do what to the file?).

But aside from those weaknesses, Wicked Cool Perl Scripts is a fine book that would be of interest to any Perl programmer, regardless of their expertise. In fact, the administrator of a Web site or a Linux/Unix server, would not even have to know the language in order to download these Perl scripts, and use them to solve problems on the job.

Michael J. Ross is a freelance writer, computer consultant, and the editor of the free newsletter of PristinePlanet.com.


You can purchase Wicked Cool Perl Scripts from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

Wicked Cool Perl Scripts

Comments Filter:
  • Re:Solve it (Score:5, Informative)

    by tcopeland ( 32225 ) * <tom AT thomasleecopeland DOT com> on Wednesday June 28, 2006 @03:44PM (#15623437) Homepage
    Yup, he's an excellent writer, and he's been cranking them out for quite a while. I've got his "Practical C Programming" book; it was written in 1991 but is still quite handy. Kind of like John Levine's lex/yacc [amazon.com] book; classic stuff. Rereading that book shows pretty clearly that domain specific languages have been around for quite a while - although maybe they're a bit easier to write nowadays.
  • Future wickedness (Score:5, Informative)

    by smittyoneeach ( 243267 ) * on Wednesday June 28, 2006 @03:46PM (#15623449) Homepage Journal
    Audrey Tang thinks that Perl6 may be here before Vista, possibly even by the holidays...
    http://pugs.blogs.com/pugs/2006/06/yapcna_talk.htm l [blogs.com]
    The slide show links show some terrifying code snippets.
    These Perl-merlins are wicked, indeed.
  • OB Ruby fanboyism (Score:2, Informative)

    by Teach ( 29386 ) * <graham@NospAm.grahammitchell.com> on Wednesday June 28, 2006 @03:52PM (#15623489) Homepage

    You know, I love Perl. I've been using it for CGI stuff, for system-administration stuff, etc, for six or seven years now.

    In fact, the only things I haven't written in Perl during that time have been things that were either too lightweight (five line shell scripts) or too in need of structure (a free/Free clone of Advance Wars in Java).

    That said, every new script I've written so far this summer has been written in Ruby. I hate to sound like a Ruby fanboy, but I think Ruby is really a better perl than Perl.

    Ruby is good at everything that Perl is good at (regular expressions, CGI, process control, text munging) and has equally rich built-in libraries. However, Ruby is also good at the things that Perl isn't good at. You've got real objects when you want them. LISP-like things like iterators and closures. The works.

    Ruby's only major flaws at the moment are: 1) it doesn't have anything like CPAN (yet), and 2) interpreter speed is still fairly slow relative to older, more optimized interpreted languages like Perl or Python.

    I do agree that Steve Oualline is a badass, and that Perl is pretty wicked.

    But you fans of Perl should give Ruby a try, especially if you know some LISP or Scheme and occasionally miss Perl's difficulty in creating something as simple and rigid as a C struct.

  • by coyotecult ( 647958 ) on Wednesday June 28, 2006 @04:06PM (#15623571) Homepage
    Worlds = world's! I know it's in a code comment, but eeeeesh. Apostrophes are friends!
  • by kisrael ( 134664 ) on Wednesday June 28, 2006 @04:12PM (#15623622) Homepage
    I've been a street-taught Perl hacker since like 1993 or so.

    Only recently, despite having read a lot of the Perl books and hung around online a lot, I found about the history of Perl that I almost couldn't believe...that originally, it was just a glue language for a big honking chunk of Unix system calls, mostly written in C.

    My credulity is because Perl sometimes seems like the anti-C...especially in terms of handling strings, since my memory of C is using chararrays for everything.

    But it makes sense.... C offered blazing speed, and Perl was a great duct tape glue for all that. It's amazing that it had such quality memory management, string handling, associative arrays, and loosey goosey syntax for reg ex etc. But it's great.

    I think it falls apart once you get to the perl 5 object model, which I've never been able to really get my head around... but for anything that should be written programatically rather than structured from objects, it's really great.
  • Re:OB Ruby fanboyism (Score:1, Informative)

    by Anonymous Coward on Wednesday June 28, 2006 @04:33PM (#15623764)
    Isn't RubyGems specifically for CPAN-like functionality? I realize it's nowhere near as mature as CPAN, but Ruby isn't as mature as Perl either, is it?

    http://docs.rubygems.org/read/book/1 [rubygems.org]

  • NOT Worth While (Score:2, Informative)

    by Anonymous Coward on Wednesday June 28, 2006 @04:34PM (#15623776)
    If you've hacked Perl for over a year this book is major disapointment. The examples are all largely available elsewhere and relatively uninspired things such as simple CGI web counters. Buy some O'Reilly stuff instead.
  • Re:Clarification (Score:1, Informative)

    by Anonymous Coward on Wednesday June 28, 2006 @04:41PM (#15623825)
    That was your statement, not your argument. You stated that Perl was such, then argued is was because of an error generated by Slashdot code. That's not exactly compelling evidence of, well, anything, except maybe that the Slashdot error messages could be more verbose.
  • Re:Evil Perl (Score:5, Informative)

    by Michael Woodhams ( 112247 ) on Wednesday June 28, 2006 @04:53PM (#15623908) Journal
    They are brute-force alphametics solvers. Save either into a file (say "s") then:
    $ perl s send+more==money
    9567+1085==10652
    9567+1085==10652

    If anyone can shorten either of these programs (even by one byte) please let me know. If you do, and you're geographically close enough, I'll buy you lunch. (Watch for bugs with numbers with leading zeros.)

    Version 1 is 133 bytes, version 2 is 103 bytes. Version 1 is almost entirely my own work, and contains a nifty recursive permutation generator. Version 2 was produced by someone else in response to my challenge, and then further compressed a bit by me.

    Unfortunately, the Obfuscated Perl Contest has disappeared (although these are principally compressed rather than obfuscated.)
  • by grcumb ( 781340 ) on Wednesday June 28, 2006 @05:52PM (#15624326) Homepage Journal

    "Pathologically Eclectic Rubbish Lister, or sometimes Practical Extraction and Reporting Language. The first one is said to have come first, and was the "real" meaning of the acronym, but I think the second one is the more "official" meaning."

    Er, no [wikipedia.org]. The word 'Perl' is a backronym [wikipedia.org].

    Wikipedia sez:

    Perl was originally named "Pearl", after "the pearl of great price" of Matthew 13:46. Larry Wall wanted to give the language a short name with positive connotations; he claims that he looked at (and rejected) every three- and four-letter word in the dictionary. He also considered naming it after his wife Gloria. Wall discovered before the language's official release that there was already a programming language named PEARL and changed the spelling of the name.
  • by Metasquares ( 555685 ) <slashdot.metasquared@com> on Wednesday June 28, 2006 @06:30PM (#15624552) Homepage
    You can write part of this program even more efficiently in Perl 6:
    sub main()
    {
    ...
    }
    It's called the "yadda yadda operator" and it is actually valid Perl 6 syntax.
  • Re:"Wicked" Cool? (Score:3, Informative)

    by misleb ( 129952 ) on Wednesday June 28, 2006 @06:45PM (#15624626)
    They can't pronounce the "d". They have trouble with "r" as well. They drive cahs. Wicket awesome cahs.

    -matthew

An authority is a person who can tell you more about something than you really care to know.

Working...