Slashdot Mirror


Wicked Cool Perl Scripts

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.

69 of 239 comments (clear)

  1. Solve it by suso · · Score: 4, Funny

    Useful Perl Scripts That Solve Difficult Problems.

    Heh, Steve Oualline. In his book on Vim, he had this example of code where the program comment went something like this:

    /*
    Program -- Solve it -- Solves the worlds problems.
    All of them. At once.
    This will be a great program when I finish it.
    */

    1. Re:Solve it by with_him · · Score: 2, Funny

      I think he used a unifed shoe string theory for that solution.

    2. Re:Solve it by tcopeland · · Score: 4, Informative

      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 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.

    3. Re:Solve it by Anonymous Coward · · Score: 5, Insightful

      "There's more than one way to do it" should not be considered a personal challange to find them all

    4. Re:Solve it by Abcd1234 · · Score: 5, Insightful

      Perl is the most wonderfully architected, elegant, flexible language in the world. It's like a fully stocked kitchen with everything you'd ever need to get the job done, and more. Any new version of Perl would be a step backwards.

      See, we can both make absolutist, arbitrary statements with no basis in reality. Fun, eh?

    5. Re:Solve it by Jerf · · Score: 2, Interesting

      Perl is an overly complicated, syntactically-challenged, unstructured kitchen sink of a language. The next major version of perl needs to be developed with more of a plan, and less of a "a little of this, and a little of that" philosophy.

      Rest assured, Perl 6 has planning in abundance.

      You'll probably be less happy to learn that the guiding principle seems to be a "lot of this, lot of that" philosophy.

      But, this time with a plan.

      (My personal call on Perl 6? It's time to just ship it. Whatever "it" is. After a while the value lost to not having anything at all outweighs the cost of shipping nothing useful. Although, honestly, I'd rather see a useful Parrot that makes it possible to run Python, Perl, Ruby, and TCL through the same VM than Perl 6.)

    6. Re:Solve it by grcumb · · Score: 3, Interesting

      "Perl is the most wonderfully architected, elegant, flexible language in the world."

      Indeed. In fact, it's the only language in the world that can guarantee perfect software, every time. Even when you're drunk. 8^)

      --
      Crumb's Corollary: Never bring a knife to a bun fight.
  2. Good Practice? by neonprimetime · · Score: 2, Insightful

    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.

    Is these really that good of a practice though? Your pc's will be jam-packed with go you never wrote ... therefore you don't know what's actually going on with your own machines? Write your own scripts script kiddies.

    1. Re:Good Practice? by Cleon · · Score: 5, Insightful

      Admins that download scripts off the Net without even checking to see how they work are a danger to themselves and others.

      --
      Gifts for Geeks - Stuff that really matters!
    2. Re:Good Practice? by iamdrscience · · Score: 3, Funny

      Right, what's with people today, running programs other people have written? How can you be in control of your system if you didn't even write your own Operating System!!

    3. Re:Good Practice? by drinkypoo · · Score: 5, Insightful
      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.
      Is these really that good of a practice though? Your pc's will be jam-packed with go you never wrote ... therefore you don't know what's actually going on with your own machines? Write your own scripts script kiddies.

      Let's try this from another angle.

      "In fact, the administrator of a Web site of Unix/Linux server would not even have to know the language in order to download Apache, compile it, and use it to serve pages."

      "Is this really that good of a practice though? Your PCs will be jam-packed with software you never wrote ... therefore you don't really know what's going on with your own machines. Write your own programs, kiddies."

      (I corrected your spelling, grammar, and punctuation errors as well.)

      Basically, your argument amounts to absolutely nothing, because it's no different from other programs. Do you REALLY think that admins typically vet every line of code on their systems? People don't live that long. Know what the difference is between a C program you don't understand, and a perl script you don't understand? The C program is compiled once, and the perl script is JIT-compiled ever time you run it.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
  3. Sweet by Rethcir · · Score: 2, Funny

    These scripts are wicked friggen' pissah!

  4. "Wicked" Cool? by necro81 · · Score: 4, Funny

    The author must be from Massachusettes, possibly the Cape?

    1. Re:"Wicked" Cool? by navyjeff · · Score: 4, Funny
      To our readers on the West Coast:

      Please replace every instance of "Wicked" with "Hella" to improve readability.

      Thank you for your cooperation.

    2. Re:"Wicked" Cool? by Darby · · Score: 2, Interesting

      To our readers on the West Coast:

      Please replace every instance of "Wicked" with "Hella" to improve readability.


      That's only the Bay area.
      Even the rest of California really wants them to quit using that stupid sounding term.

    3. Re:"Wicked" Cool? by misleb · · Score: 2, Informative

      They can't pronounce the "d". They have trouble with "r" as well. They drive cahs. Wicket awesome cahs.

      -matthew

      --
      "THERE IS NO JUSTICE, THERE IS ONLY ME." -Death
  5. yes and no by JeanBaptiste · · Score: 5, Insightful

    While it is important that the Admin completely understands what is going on.... theres no need to re-invent the wheel if someone else already went through the trouble of writing and testing it.

    1. Re:yes and no by finkployd · · Score: 5, Funny

      Personally, I don't think you truly understand how a wheel works until you reinvent one :)

      Finkployd

    2. Re:yes and no by finkployd · · Score: 3, Insightful

      I have not gone that far but I did write my own weblog in c forgoing the use of any libraries (like cgic) to make sure I knew exactly how web apps communicate with browsers. I didn't have to but now that I am rewriting it as a java servlet I have a much better understanding of what is going on behind the scenes.

      DIY is not always the answer, but in cases where the person is doing it for their own education I don't see a downside. There is also a compelling reason to do it for administration scripts were you will be responsible for fixing anything that breaks.

      Finkployd

    3. Re:yes and no by poot_rootbeer · · Score: 2, Insightful

      I agree that an admin need not reinvent the wheel, if pre-built wheels are readily available. But he should inspect it to make sure it's actually a wheel, and not just a pie pan, before he bolts it into the axle. Or at least know what a wheel looks like.

      The grandparent excerpt reads "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" -- implying that the admin not only doesn't need to WRITE the scripts he runs, but also doesn't need to READ the scripts he runs. That is foolish.

  6. Re:All I want to know is... by neonprimetime · · Score: 4, Funny

    The Book? Of course ... but you'd need a power supply, motherboard, hard drive, processor, & memory

  7. Perl glue by Anonymous Coward · · Score: 3, Funny
    Perl has been called the glue that holds the Internet together.

    Hey, wait a minute! That's not glue... ewww... what is that? Larry, have you been touching yourself again?

    1. Re:Perl glue by tool462 · · Score: 2, Funny

      There's more than one way to do it ;)

  8. Future wickedness by smittyoneeach · · Score: 4, Informative

    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
    The slide show links show some terrifying code snippets.
    These Perl-merlins are wicked, indeed.

    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  9. Let the religious flamefest begin! by mmell · · Score: 3, Funny
    In this corner - advocates of Perl, the Pathologically Ecclectic Rubbish Collector (or something like that)

    In that corner - advocates of Ruby (I haven't got a clue on this one, folks)

    And in this corner - dinosaurs like myself who still think awk/sed/sh is a pretty neat thing. Wait a minute, that's three corners. Uh . . .

    1. Re:Let the religious flamefest begin! by Bromskloss · · Score: 4, Funny
      And in this corner - dinosaurs like myself who still think awk/sed/sh is a pretty neat thing. Wait a minute, that's three corners. Uh . . .

      Weep not, brave one, it's called a triangle and is perfectly normal.

      --
      Swedish plasma phys. PhD student; MSc EE; knows maths, programming, electronics; finance interest; seeks opportunities
    2. Re:Let the religious flamefest begin! by richdun · · Score: 2, Funny

      Ruby - Really User-friendly Buzzword Yeah!

      I dunno. Maybe that's why so many use redundant acronyms - one less word to think of.

    3. Re:Let the religious flamefest begin! by grcumb · · Score: 2, Informative

      "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. The word 'Perl' is a backronym.

      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.
      --
      Crumb's Corollary: Never bring a knife to a bun fight.
  10. Perl? Bah! by Anonymous Coward · · Score: 5, Funny

    Anyone worth their salt would use an AJAX web 2.0 implementation of ruby on rails with a J2EE backend running struts marked up with DXHTML all bound together with an XML-SOAP web service to do their system administration via a proxied web cache. Changing configs would just involve editing a little CSS.

    1. Re:Perl? Bah! by richdun · · Score: 2, Funny

      I tried viewing this comment in IE, and all I got was a "BUZZWORD OVERRUN ERROR"

      Well done.

  11. Is this more useful by stratjakt · · Score: 4, Insightful

    Than googling for cool perl scripts?

    I'm asking seriously, because of all of the "cookbooks" and collection books of this sort that I've seen on the shelves at Borders, they're all full of things that a quick bit of googling could come up with. In fact, a little searching usually yields better solutions, and I'm convinced they're written by copy/pasting google results into the author's editor of choice.

    I'm all for good dead-tree reference material, but I've been frustrated trying to find books that don't contain stuff-i-already-know, or stuff-i-can-get-free on the 'net.

    I guess it can't be good for the dead tree tech manual industry, but so long as universities and colleges force students to buy the books (and a new revision of the same book every year), that's all fine and good.

    --
    I don't need no instructions to know how to rock!!!!
    1. Re:Is this more useful by Tankko · · Score: 3, Interesting

      I have a bunch of "cookbooks", and I don't read them because I'm looking for a specific solution, I read them because it's a great way to learn a lot of tricks and see a lot of code in a concentrated place that covers a bunch of areas.

      I sit on the couch and just read them and learn a lot.

  12. Solve it, Fixed version by fprog26 · · Score: 2, Interesting

    Your solution was a bit too C++ and won't compile with perl, so you probably meant the following... :)

    #!/usr/bin/perl
    #
    # Program -- Solve it -- Solves the worlds problems.
    # All of them. At once.
    # This will be a great program when I finish it.
    #

    sub main()
    {
    # no idea at all...
    }

    main();
    exit;
    1;
    __END__

    or the even better, the POD way:

    #!/usr/bin/perl

    =head1 GOAL
    Program -- Solve it -- Solves the worlds problems.
    All of them. At once.
    This will be a great program when I finish it.
    =cut

    sub main()
    {
    # no idea at all...
    }

    main();
    exit;
    1;
    __END__

    1. Re:Solve it, Fixed version by Anonymous Coward · · Score: 2, Funny

      #!/usr/bin/python

      from __future__ import solutions

      solutions.solveTheWorldsProblems()

    2. Re:Solve it, Fixed version by rgmoore · · Score: 5, Interesting

      That looks as though you don't know Perl very well. There's no need for a separate main routine, as whatever is in the file that's not part of another subroutine is assumed to be part of main. There's also no need to have the program end in a true statement (that's necessary only for modules) or to use an __END__. In the true spirit of Perl (i.e. eliminating needless elements) here's a refined version:

      #!/usr/bin/perl

      =head1 GOAL
      Program -- Solve it -- Solves the worlds problems.
      All of them. At once.
      This will be a great program when I finish it.
      =cut

      use warnings;
      use strict;

      #Do something here

      exit;
      --

      There's no point in questioning authority if you aren't going to listen to the answers.

    3. Re:Solve it, Fixed version by eln · · Score: 5, Insightful

      The exit statement at the end is unnecessary.

    4. Re:Solve it, Fixed version by Metasquares · · Score: 2, Informative
      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.
  13. OB Ruby fanboyism by Teach · · Score: 2, Informative

    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.

    --
    Graham "Teach" Mitchell, computer science teacher, Leander HS
    1. Re:OB Ruby fanboyism by Billosaur · · Score: 2, Insightful
      However, Ruby is also good at the things that Perl isn't good at. You've got real objects when you want them.

      Hey!! Perl has real objects... you just have to work at it...

      Of course, being a Perl programmer, I am very averse to work, hence all the time I spend reading Slashdot.

      --
      GetOuttaMySpace - The Anti-Social Network
    2. Re:OB Ruby fanboyism by nuzak · · Score: 4, Insightful

      I have those two reasons, but those are soft factors, nice-to-have, but not necessary. Unfortunately, I have a third:

      3) unicode

      I have to deal with lots of unicode, index it, run regexes on it, and so on. Ruby lacks any real unicode support, which has made it a deal-breaker.

      --
      Done with slashdot, done with nerds, getting a life.
    3. Re:OB Ruby fanboyism by loquacious+d · · Score: 2, Interesting

      I agree on all points. I also find the average Ruby script infinitely more readable than most of the Perl I've read (or written). Ruby's syntax is just so perfect and clean. I was pretty skeptical when I first started reading Ruby books, the way everyone always waxed so ridiculously lyrical about how writing Ruby after using other languages was like a walk in a park on a damp spring day with the sun just barely shining through the low wispy fog etc. etc. etc. But it's true. I hope it can maintain its momentum, the world would be a better place if people spent as much effort learning/improving/extending Ruby as they did Java (*shudder*).

    4. Re:OB Ruby fanboyism by glwtta · · Score: 3, Insightful

      You've got real objects when you want them. LISP-like things like iterators and closures. The works.

      I don't want this to degenerate into rabid fanboyism, but it seems the benefits of a "real" (or, real, if you preffer) object system over Perl's are routinely exaggerated. Yes, it could be better, but for 95% of the things you do, it works just fine.

      And of course Perl has iterators and closures (and first order functions, and all that other hard-to-maitain stuff the Functional crowd always goes on about). It's probably one of the things I like best about Perl, it just has features as part of the language, no one makes a huge deal of it.

      I've looked at Ruby (ok, glanced), and I just can't stomach the syntax - it's like writing Java in VB. Entirely subjective, of course. Though, as long as I live I will not understand this recent fad of trying your best not to delimit code blocks clearly - it smells of choosing ideology over utility.

      Definitely agree about the lack of "simple and rigid" struct-like things, I miss those often.

      And of course for anyone who wants a feature that Perl doesn't have, there's Perl 6 - that will have every feature that has existed in any language, ever.

      --
      sic transit gloria mundi
    5. Re:OB Ruby fanboyism by esper · · Score: 3, Interesting

      "Inside-out objects" can give you hard data hiding. Basically, instead of storing the object properties as keys of a blessed hash, you have a file-scoped (my) array for each property. Nothing outside of that file can access the data and the object becomes a blessed integer reference (used as an index into the property arrays) instead of the blessed hash reference that's normally taught. (This can also be implemented with hashes for each property and the blessed reference itself used as the hash key, but I tend to prefer the array version, since the lookups are a good deal faster.)

    6. Re:OB Ruby fanboyism by myowntrueself · · Score: 2, Funny

      My understanding is that Perl doesn't have real objects, it just lets you pretend that it has objects, and everything basically works.

      s/objects/anything/g

      --
      In the free world the media isn't government run; the government is media run.
  14. Fine, but about the title... by danelav · · Score: 2, Insightful

    Why is it that every scripting book needs a title that sounds like it was written by a 14-year old?

  15. Gaah, that was in a book? by coyotecult · · Score: 2, Informative

    Worlds = world's! I know it's in a code comment, but eeeeesh. Apostrophes are friends!

  16. Re:Overhyped by maximthemagnificent · · Score: 2, Interesting

    I learned perl coming from a c++, Java background and I found it really, really ugly.
    Not that I've learned any other scripting languages to have some comparison, admittedly.

  17. the relationship between Perl and C by kisrael · · Score: 2, Informative

    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.

    --
    SO YOU'RE GOING TO DIE: The Comic for Dealing with Death
    1. Re:the relationship between Perl and C by Phroggy · · Score: 4, Insightful

      I don't see how you could read any books about Perl and not have any idea where the language came from. This is why PHP is so much more popular than Perl among people who don't already have a familiarity with UNIX and C: a C programmer learning Perl can say "oh hey, perl has a localtime() function, I already know how to use that" while a newbie will say "wtf, why do months start with 0 and the year is 106, and how am I supposed to remember what order all these numbers are in?" A UNIX hacker can say "oh hey, $0 and $$ are exactly the same as they are in shell scripts, and the regex syntax looks just like sed" while a Windows user will say "wtf, what are all these meaningless variables, and what the hell is a regex?"

      My advice for OOP in Perl:
      1) learn how OOP is supposed to work in some other language
      2) pretend that it works that way in Perl, and try not to think about how "bless" actually works.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
  18. Perl praise and beefs interspersed by tinker_taylor · · Score: 5, Insightful

    A humble Perl user's thoughts on this brouhaha --

    Praise
    =======

    1) The power of perl is irrefutable -- it helps slap together quick and clean solutions to irritating admin problems. The flip-side of being a perl jockey I guess is that one tends to try and create a solution to many a problem that already has a solution - because searching CPAN can be a pain at times.

    2) Use of the more flexible features of the languages (such as Hashes, hash of hashes etc) data/number munging and organization becomes more manageable.

    3) Using Perl's almost endless modules, a lot of relatively complicated tasks can be simplified.

    4) Annoyance factor of numerous tasks (especially Administrative and reporting) can be reduced drastically with the help of Perl.

    Beefs
    =====

    1) The beef I guess is that unlike Python or Perl's other competitors, Perl modules don't come tightly integrated with the core distro. Agreed that Perl probably has a lot more modules than any of those other languages do, but a larger than ordinary de facto distribution (why not include important modules like Digest::MD5, Crypt modules, SSH modules etc?) would be desirable (especially in those situations where you don't have access to the internet directly from within corporate networks and can't install the modules with the "perl -MCPAN -e shell" option) . There might be those Perl veterans who would say -- "build your own distro with your custom modules already packaged" -- and while that might be a very smart thing to do, many a time (when one keeps moving from one environment to another -- some call it job hopping, it helps to be able to download one single perl distro package or rpm or the source+compile and have basic administrative scripts work -- especially those that rely on centralized automation (ssh-based trusts, copies across the network, etc).

    2) Also, perl's syntax can be terse and difficult for noobies to understand (or even older perl-hands for that matter -- when someone has written code without appropriate comments, etc).

    3) Tinkering with Python recently, I found it's simplicity refreshing and it's syntax easier to comprehend (especially when compared with Perl's (imho) complicated "scoping" requirements, etc).

    4) Sometimes (and I guess it depends on the person writing the code) Perl tends to over-complicate things that can be easily handled via Shell scripts.

  19. Re:Clarification by Vorondil28 · · Score: 3, Interesting
    You're argument against Perl is:
    1. Slashdot is written in Perl.
    2. I don't understand the error message I got when attempting to post on Slashdot.
    3. Therefore, Perl code is incomprehensible and unmaintainable.


    You, sir, are a veritable fount' of wisdom...</sarcasm>
    --
    This sig rocks the casbah.
  20. I'm not impressed by cerelib · · Score: 3, Insightful

    It seems as if all they did was wrote a basic clock program and then ran it through an obfuscator or two. You can get a few obfuscation modules on CPAN. Anybody can run a program through obfuscators. Ever tried to look at the google maps javascript?

  21. NOT Worth While by Anonymous Coward · · Score: 2, Informative

    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.

  22. Write yes, read not so much by Sarusa · · Score: 3, Interesting

    'Of all the popular programming languages now in use, Perl is perhaps the best suited for writing utilities'. I would probably agree with this - you can very easily hack out a very simple utility to do something with less effort and code than in Ruby or Python. Of course if you ever need to read it again, or god forbid extend it, then the extra effort you put in up front may pay off.

    Yes, I know you can write very readable maintainable perl. In theory. The only example of this I have ever seen is the Calcium web calendar. But whenever our perl guy writes something it looks more like
        ($l=join("",))=~s/.*\n/index($`,$&)>=$[||print$&/g e;
    (stolen from http://www.antipope.org/charlie/attic/perl/one-lin er.html) and if he has to touch it again a month later it's a dangerous thing.

  23. My Ex-Language by tedhiltonhead · · Score: 4, Funny

    Perl is like my ex-girlfriend... I used to be all over her^H^H^Hit but am now fawning over the knockout redhead Ruby. Unfortunately, I had several children with my ex that still need to be cared for -- feature improvements, bugfixes, restarts. Hopefully one day they'll grow up and leave the house so Ruby can have me all to herself.

    1. Re:My Ex-Language by esconsult1 · · Score: 4, Interesting
      So right.

      Look over the perl 6 syntax and the increased punctuation, then compare to Ruby. I've been working with perl now for about 10 years or more, and Ruby has replaced or supplanted all my Perl work over the last several months. No going back. Not even bothering to learn Perl 6. CPAN is sweet, but so much is already built into ruby's standard libs.

      Ruby syntax is clean. Real OOP. Self documenting. No way I'm going back, especially not for Perl 6, which is too much, and too late.

  24. Evil Perl by Michael+Woodhams · · Score: 3, Interesting

    Version 1:
    @a{($b=pop)=~/\w/g}=@a=0..9;$a="@{[keys%a]}";sub
    a{@a?map@a=(a(@_,pop@a),@a),1..@a:($_="$b
    ",eval"y,$a,@_,",/\b0/)||eval&pop}a

    Version 2:
    while($_=$a=pop){/([a-z])/i?map{($t=$a)=~s/$1/$_/g ;$a!~/$_/&&push@ARGV,"$t
    "}0..9:/\b0\d/||eval&&print}

    They do the same thing. I'll post what that is in a follow-up, for the sake of any masochists who want to figure it out for themselves.

    --
    Quattuor res in hoc mundo sanctae sunt: libri, liberi, libertas et liberalitas.
    1. Re:Evil Perl by Michael+Woodhams · · Score: 4, Informative

      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.)

      --
      Quattuor res in hoc mundo sanctae sunt: libri, liberi, libertas et liberalitas.
  25. Re:Now that is a cool poll by audreyt · · Score: 5, Funny

    ...and I would be inclined to agree. :-)

  26. Perl is VB by Anonymous Coward · · Score: 2, Interesting

    I'll preface by saying that there's nothing inherently wrong with VB or with Perl. The problem occurs because both *can* foster poor programming practices. Both have an immense library of functions that allow novice scripters to hack together scripts that can perform a function. There may not be any overall design, but for lots of folks, this is more than enough. The problem occurs when you try to maintain that code (either Perl of VB) and you realize that people have pulled together modules (or ActiveX contols) that do the job, but are probably the worst or next-to-worst way of doing things. In other words, Perl and VBs downfall is their success.

    It just seems that other languages (Java, Ruby, Python) are more rigorous -- maybe because the learning curve is *slightly* higher. It's easier to write proper code in these languages because the design of the language almost enforces it.

  27. C is the glue... by Fleeced · · Score: 3, Insightful

    In fact, Perl has been called the glue that holds the Internet together.

    That's not true. C was considered the glue of the Internet... Perl is the gaffa tape.

  28. As much as I hate granting time to the Perl haters by Borf · · Score: 5, Insightful

    I'm giving in this time.

    I work in a shop where we maintain (after last count) 112,002 lines of perl in a single system (which also contains about half a million lines of C).

    Guess what? It's not a problem! Not in the slightest!
    And you know why?

    - Modules
    - Coding conventions
    - Mature programmers

    Two of those three are redundant. Take a guess which ones (the third item isn't part of the anwer set).

    If you take a programmer that writes disciplined, careful, extensible, extendable and professional C - are they going to start generating hacked up crap when they switch to Perl? No. They're not. They split source among modules. They use naming conventions. They use strict. They use the namespaces. They use clear syntax. The end result looks almost like C most of the time. Except when it doesn't, 'cause it's Perl.

    What does C written by hack-job Perl "programmers" look like?

    Rephrasing #37 - "It ain't the arrow, it's the (Native American)".

  29. You need a new perl guy by Wee · · Score: 2, Insightful
    But whenever our perl guy writes something it looks more like ($l=join("",))=~s/.*\n/index($`,$&)>=$[||print$&/g e; and if he has to touch it again a month later it's a dangerous thing.

    Fire your perl guy -- he's clearly a menace. And after you fire him, tell him to stop reading perlmonks.org. After a while, he'll start doing things like using foreach() instead of map() when it makes the script clearer. And as an added bonus, he won't waste time trying to find the bug he caused from overwriting $_ with a regex or whatever.

    There's no reason not to write maintainable code, perl included. That you get the choice with perl is a design goal of the language, and it's a good thing in general. But why neophytes always try to put the newest, cleverest toy they discovered into every script they write is beyond me...

    -B

    --

    Ash and Hickory, straight-grained and true, make excellent bludgeons, dandy for the cudgeling of vegetarians.

  30. Ruby's syntax *SUCKS* by mangu · · Score: 2, Interesting
    Ruby has the completely useless "end" statement they borrowed from FORTRAN77 and Ada. Stupid, stupid, stupid, how stupid can you get?


    Every text editor I know and use can match braces. Where does this block end? By clicking one or two keys I immediately know. I have no idea (and I really don't want to know) how do you match a generic "end" with the corresponding block opener in Ruby.


    Do you think this is unimportant? If so, you aren't a professional programmer, and it's OK for you to use that toy language, Ruby. But if you do coding for a living you understand how important it is to get things right with the least effort. The time you waste fighting the Ruby syntax could be used to write more code.


    Once you really learn a language like Perl or C you stop worrying about that dreaded "more than one way to do things", because you find which is your preferred way and stick to it. Once you truly understand C pointers you start to appreciate the way they let you code more efficiently the type of real-world applications that textbooks cannot present for lack of space.


    C and Perl are for professional programmers. Ruby and Python are for people who need to write short programs from time to time, better than VB, of course, but no substitute for professional quality tools.

    1. Re:Ruby's syntax *SUCKS* by Dasher42 · · Score: 2, Insightful

      C and Perl are for professional programmers. Ruby and Python are for people who need to write short programs from time to time, better than VB, of course, but no substitute for professional quality tools.

      I have to call BS on this one. I highly doubt that the parent poster has seen the ubiquitous pile of legacy Perl code lying around, and how bad and bug-ridden it can be because the programmers didn't do enough to control a sloppy language. I think Perl Medic is the only Perl book I'll ever recommend for that reason.

      Based on years of professional and hobby experience, I'd keep Perl around for 100 line one-off scripts and no more. Perl's flaws as a language have bit down hard anywhere where multiple programmers had to collaborate on a sizable project or maintain it over a period of time. The amount of nonsensical boilerplate is tremendous. Having to shovel more of it to force what is essentially an sh script with everything in the world tacked on just to keep its variables non-global is the precise opposite of what a serious language should do. And the language even lets a freestanding next or last statement in a function break loops in the calling function! Try being on a team with sloppy programmers with those kind of design flaws running loose.

      That was the past. I now work in a Silicon Valley startup where we use Java and Python, depending on the kind of work being done. Python's design scales far better for application development, with good modularization and OO done right without extra judo moves just to force behavior. The Ruby and PHP people seem pretty happy too.

      Perl was good in its day. Other languages have long since surpassed it. Let it go the way of COBOL.

  31. Re:Clarification by mrsbrisby · · Score: 3, Insightful

    Seriously. Incomprehensible and unmaintainable code can be written in any language, but in Perl even good code is unreadable.

    It can be unreadable, but that doesn't mean that it is. Code can be good for lots of reasons- not just legibility :)

    Perl is probably the language with the highest chance of accepting the output of a random number generator as a valid program.

    That honor belongs to sendmail; We used to offhook the telephone couplers whenever someone had messed sendmail.cf up to get a good working setup from the line noise that'd leak through.

  32. It occurs to me... by Ayanami+Rei · · Score: 3, Insightful

    I've seen a lot of both.
    Really shitty, unreadable Perl that makes your head hurt. Stuff that was only designed to execute from top to bottom like a shell script and it only works in the context of some main file. Won't even run if you use sttrict.
    And beautiful, expressive object-oriented, properly packaged stuff that lets you plug and test it any which way. Stuff you aren't afraid to instrument, modify, or implement because you just understand the author's intent.

    They look almost like two different languages.

    Then again, I think this is what happen when you have languages that have a lot of built in functionality blessed with tersity and "reasonable defaults".

    You can't write spaghetti code in a more structured language like Java or C that does anything useful without code generation.

    Perl makes it possible even without syntax highlighting.
    It's _too easy_ on the programmer.

    *shrugs*

    It's like VB... except you had a web GUI with a simple "use CGI". And pervasive regular expressions (which, IMHO, is the thing that makes perl unreadable if you don't learn about the m//x modifier).
    In 1999.
    So anytime you go online searching google for a Perl script that does XYZ, you end up on one of those code-sharing sites full of "consultants" idiots and you've got the worst kind of code floating around there. Copy and pasted crap with no structure... just hacked up until it works.
    And Perl's permissiveness allows it to proliferate.

    I just write everything myself, or get it from CPAN.
    CPAN at least acts as a kind of quality control.

    If you want to see how to write or model your code, use CPAN modules as examples. You learn alot.

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON
  33. Re:As much as I hate granting time to the Perl hat by mrsbrisby · · Score: 4, Funny

    What does C written by hack-job Perl "programmers" look like?

    Java.

  34. *shrugs* by Ayanami+Rei · · Score: 2, Insightful

    For the most part the POSIX C API uses NUL terminated strings, pointers to structs, and ints (and opaque types that are actually ints). Oh, and small structs made up of that stuff.
    Perl's scalar numbers internally are the same size as the system's ints, so that handles that detail.
    Perl auto-coerces strings to numbers and vice-versa. So it can handle the number and string arguments using built-in API functions that just take whatever perl expression and coerce it down to the appropriate scalar context in the glue code. Functions that wanted structs and pointers to them (say, like gettimeofday, select or localtime) would be handled at function call time -- the memory allocated only lasted as long as it was needed to issue the call and copy the return value into the result array for the caller.
    You had to actually include perl modules that defined all the constants you would otherwise get from say, stdio.h or sys/types.h since perl didn't know about them (like O_RDWR, SEEK_SET, and all that stuff). Or you could hardcode constants. :-D

    Yeah, and you'd read Perl man pages and they'd caution you how the behavior of a lot of those bare functions were OS dependant, subject to the OS's specificities (AIX, Linux, Solaris, VMS and Windows, Oh My!). I.E. Linux's select would modify the time left to wait, while Solaris's didn't specify either way (until they introduced pselect(), which didn't, and changed select() so it always did).
    Which is why the invented Perl IO and IO::Socket, and they introduced "Perl threads" -- so you could do stuff that was close to bare metal without worrying about niggling platform details.

    --
    THIS THING CAN TURN ON A DIME, MACROSSZERO STYLE ALSO FUCK BETA, ~NYORON