Slashdot Mirror


Randal Schwartz's Perls of Wisdom

r3lody (Raymond Lodato) writes "Anyone who has been working on the *nix platform has had a brush with Perl, the scripting language whose acronym (depending on who you ask) could mean Practical Extraction and Report Language, or Pathologically Eclectic Rubbish Lister. In either case, there is a distinct difference between learning to use Perl, and learning to use it well. In my opinion, the best way to learn any language well is to see how others have used it to solve problems. One of the foremost experts in the use of Perl, Randal L. Schwartz, has been writing columns since March of 1995 on the use of Perl in the real world, and has provided us with 6 books and over 200 columns with many examples on how Perl is used." Read on for the rest of Lodato's review. Randal Schwartz's Perls of Wisdom author Randal L. Schwartz pages 350 publisher Apress rating 7/10 reviewer Raymond Lodato (rlodato AT yahoo DOT com) ISBN 1590593235 summary A dated compendium of the best of Randal's Perl columns

Perls of Wisdom is a collection of 65 selected columns from Linux Magazine, Unix Review, and the now-defunct Web Techniques magazines, written between May 1995 and July 2004. In each column, Randal discusses some problem that he had to solve, or that someone else needed help in solving. He carefully discusses the problem, and then shows the Perl code needed to resolve it. Many of the columns are complete applications that can be run (with minor modifications) by the reader. (The listings are also available from the apress.com web site.) Each column has been reproduced as it was written in the original magazine, with "Randal's Note" prepended. Therein lies this book's best feature and greatest flaw. Allow me to explain.

When I first picked up this book, I had only read a couple of Randal's columns (from Web Techniques), and saw that he wrote tutorials of proper Perl usage. He also relies on the wealth of modules submitted to CPAN to leverage a solution. After all, why reinvent the wheel? I expected to see more commentary on the reasons behind choosing one solution over another, or insights into the inner workings of Perl itself. I more or less got what I expected. For example, the first column reproduced in the book (It's All About Context) explains why, when someone used my ($f) = 'fortune'; instead of my $f = 'fortune'; he got in trouble with the law (see the book to understand the legal issue). The first form only retrieves the first line of the output of the fortune program, while the second form retrieves the entire output. Little items such as scalar versus list context can trip many Perl coders.

The first chapter (Advanced Perl Techniques) does give you many tips and insights like the example I just gave. All but two of the twenty columns are little tutorials on the ins and outs of handling the commonplace day-to-day issues that Perl can address with ease. Some delve into more obscure topics, such as the difference between shallow and deep copies of structures, and Perl's Taint mode. Two columns contain complete programs. One extracts the text from the man pages and determines their "fog" index (a measure of readability). The other creates a mirror of files needed by CPAN.pm to install new modules. For each program, Randal gives the entire listing as well as an almost line-by-line description of how it works. Each column is written in a conversational style that is easy to read, yet doesn't talk down to you.

The following chapter is comprised of seven tutorials on the various aspects of searching, sorting, and formatting text. In addition to describing the creation and compilation of regular expressions, Randal also discusses formatting and the nifty "Schwartzian Transform" (Perl's map-sort-map idiom for sorting on almost anything) which was named for him, but not by him. While some of the information is a little long-in-the-tooth (the column on Text-Processing was written shortly after Perl 5 was released), it's all interesting and educational nonetheless.

Chapter 3 starts refocusing the use of Perl to web sites. This chapter discusses HTML and XML processing in six little columns. He shows how to generate a web page index, producing a web page calendar from a file of events, and parsing XML to retrieve the data within. He also includes a lesson on how to use Perl to compare two arrays to create an HTML-formatted difference table.

The next chapter demonstrates that Randal has spent a lot of time working out ways to update and improve his web site. It covers the intricacies of CGI programming in Perl. All but one of the fifteen columns are complete programs (again, available from apress.com) with line-by-line commentary. The programs do implement mostly worthwhile functionality, but each column was pretty much "I had this problem, so I wrote this program. Lines 1-3 do this; lines 4-5 do that, etc." Granted, some of the programs are pretty nifty (check out how he automatically keeps track of the "What's New?" pages), but the reading of one program after another started to become stale.

The final chapter is titled "The Webmaster's Toolkit," consisting of fourteen programs and three tutorials. Randal covers diverse web server background topics such as creating a light-weight load balancer, random links, and forcing users to enter through the "front door." There are also instructive techniques for throttling your web server's usage of the processor (a necessity at the time for Randal, as his web site was co-resident on a server with others), and calculating download times.

In its entirety, Perls of Wisdom contains 65 columns, split roughly half-and-half between tutorials and fully commented programs. More than half of the columns show that Randal uses Perl for web processing more than for general scripting, data reduction and reporting. His tutorial articles are top-notch, but I have a quibble over his program articles, which are somewhat dated. There were a number of prefaced notes to the effect that today he'd do it differently with some new feature or CPAN module. I really wish he had actually updated the column to show the new coding techniques. The original code is interesting in the historical sense, but I wanted to see nuggets of Perl wisdom for me to use in my daily job. The writing style is fine; the bits of insight are useful, but many of the programs are too specific to problems you or I may never see, and were solved in code that's showing its age. I'm glad I got to read the book, but I think it only rates a 7 out of 10.

You can purchase Randal Schwartz's Perls of Wisdom from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

61 of 282 comments (clear)

  1. CGI programs by JaxWeb · · Score: 5, Informative

    I first learn Perl with the aim of creating dynamics webpages. I learnt from the tutorial Picking Up Perl - this is great and taught my most I needed to know with regard to the language - but it didn't teach me how to use it for websites.

    I picked up from code lying about how to read and write files, get post/get data, and so forth, and slowly built up into quite a good Perl programmer (I suppose. Not amazing, but quite fluent). This wasn't easy though and was slow. Why? I never got taught, all in one place, how to do that. I think this is what this book is trying to do - but with a much wider range than just CGI programs (although it doesn't seem to neglect it, either).

    I tried to write my own tutorial for using Perl in webpages to try and help. I'm not going to link to it here though, because it is quite terrible (I was 14 when I wrote it).

    After learning Perl, and being able to use it, there is always using the standard librarys. For this, PerlDoc has been so helpful to me.

    --
    - Jax
    1. Re:CGI programs by stu42j · · Score: 2, Informative

      PerlDoc.com is (was) nice but perldoc.perldrunks.org actually works!

  2. Link to Randal's Articles by Matt+Perry · · Score: 5, Informative

    Since there wasn't a link to Randal's collection of articles I'm providing one here. There's some excellent stuff in there.

    --
    Slashdot: Failed Car Analogies. Amateur Lawyering. Anecdote Battles.
    1. Re:Link to Randal's Articles by wmshub · · Score: 4, Interesting

      Give it a rest. I was a coworker of Randal at the time that he committed his felonies. My opinion, which was shared by the other coworkers I spoke with ath te time, was that he was guilty of two things: lack of common sense combined with making enemies within the organization.

      As an aside, he was probably the best sysadmin I ever worked with. When you wanted something done, he got it done.

    2. Re:Link to Randal's Articles by merlyn · · Score: 4, Informative
      Thank you for that. Stupid, yes. Forgot to tell my boss everything I was working on, yes. Perhaps a bit self-serving, looking for unrequested things that'd be "good for the company" so that I'd get hired longer and more often, yes.

      But intending harm, no.

      "No harm, no foul."

    3. Re:Link to Randal's Articles by merlyn · · Score: 2, Interesting
      I might be inclined to agree. {grin}

      I'm still suffering from that, in a sense. It did a big dent in my net assets, as well as make it harder for me to work. There are still countries that won't let me enter, although it's not a US restriction on my travel any more. There are also people that cannot (by company policy) hire a felon, so I'm ruled out there too.

      But, I've tried to make the most lemonade from the lemons I've been given.

  3. Reading Perl code? by treerex · · Score: 3, Insightful

    Because of Perl's TIMTOWTDI mantra reading other people's code can be an exercise in frustration, IMHO, because to grok what they have written you may end up delving into some of the more baroque syntax in the language. I've found that many people like writing incredibly terse code which makes its readibility incredibly difficult. While Schwartz may write comprehensible Perl, I expect that the bulk of Perl code in the wild is anything but. This is my biggest peave with the language, and how it can pride itself on this "feature" is beyond me.

    1. Re:Reading Perl code? by eln · · Score: 5, Insightful

      A good programmer will write readable code in any language he's writing in. Yes, there is a considerable faction who delight in making Perl code as obfuscated as possible, but it certainly doesn't have to be that way. C allows you to write some pretty ugly code too, but that doesn't make it a good idea to do so.

      The TIMTOWTDI ethos is ultimately what makes the language as useful as it is. The more ways there are to do things, the more things you can do with a little creativity. The Perl language is abstracted, as all higher level languages are, but it's forgiving enough to allow you to do things that may not be possible in other languages without a great deal of pain.

      The myth that all Perl code is unreadable is preposterous. I've written several very complex pieces of code in Perl that are not any more difficult to comprehend than any piece of C code designed to do the same thing, and often much less so. The phenomenon of obfuscated code is a result of poor programmers (and a pervasive subculture), not of the language.

    2. Re:Reading Perl code? by smallpaul · · Score: 3, Interesting

      A good programmer will write readable code in any language he's writing in.

      The world does not break down into three distinct camps: "Non-programmers", "Good programmers" and "bad programmers". Actually there is a spectrum and all programmers live somewhere along it. A language can encourage readability or discourage it. What does Perl do?

      The TIMTOWTDI ethos is ultimately what makes the language as useful as it is. The more ways there are to do things, the more things you can do with a little creativity.

      I'm sorry, one does not follow from the other at all. If I added a "+++" operator to C that increments by two then I now have at least three (obvious) ways to increment by two. Does that mean that I can now be more creative in C?

      The myth that all Perl code is unreadable is preposterous.

      Nobody claimed that in this thread.

      I've written several very complex pieces of code in Perl that are not any more difficult to comprehend than any piece of C code designed to do the same thing, and often much less so.

      Strange that you use C as your benchmark. How about a language designed in the last twenty years with readability as a goal? Perhaps Java, Python, Ruby, O'Caml, Haskell, etc.

    3. Re:Reading Perl code? by treerex · · Score: 3, Interesting

      I agree with everything you say, though some languages make writing read-only code easier than others. APL comes to mind immediately. I did not intend to convey the fact that Perl was unreadable. Rather I feel that Perl gives you more rope to write unreadable code than other languages, like Python.

      Of course you can write some incredibly terse code in Python too, especially with recent language additions.

      And I would not include C in a list of languages for writing readable code in.

    4. Re:Reading Perl code? by Anonymous Coward · · Score: 2, Interesting

      I completely understand your point and can even agree to a certain degree. I think what most people fail to understand about Perl's appeal is that most of the structures in Perl that drive some programmers nuts are ideas that are borrowed from natural languages and aren't found often in other programming languages.

      If you think about the idosyncracies in English (or any natural language), it's really a miracle that we can communicate with each other at all, and Perl's adoption of context and implied default variables is very similar to methods used in natural languages to make communication more succinct.

      And therein lies its appeal for some people. It's a language that you can just write, much the same way that you would write a paragraph or sentence. Most programming languages are highly structured complex sets of instructions. Perl is an actual language, and writing Perl feels more like writing English (once you become literate in the language that is).

      I think Perl appeals to hackers who like to write. I think Perl flexes some of the same mental muscles that writing and speaking flex and therefore appeals to people who tend to think in language-centric ways. It also probably explains why the primary strength of this idiosyncratic, language-like programming tool is processing text and text-like patterns. It just appeals to people who are linguistically minded and was developed with language interpretation in mind.

      That doesn't make it good or bad IMHO. It just makes it one way to approach the problem of programming. We're always talking about ways to make programming better. Using graphical tools and other advanced CASE tools to make it less like writing assembly code and more like writing a real language or doing some other non-technical task that we're already used to. Perl is an example of one way to accomplish that goal.

      It appeals to a certain mindset so it's obviously not for everyone, but that's what happens when you try new things (though I guess you could hardly call Perl new anymore). Same thing with LISP, it's a really really advanced high level language, but a large number of programmers hate it despite its power and advantages. It approaches the programming problem from a different angle and provides a unique solution that some people like and others just plain don't.

      I personally wish there were more languages like Perl and LISP to be honest. They're not always the most practical for all situations and I certainly wouldn't write every of my applications in either language, but they show us that's there more to programming than just C-like syntax and pointer arithmetic. And sometimes, really good ideas do come out of the fruit loop languages and find their way into other development tools.

    5. Re:Reading Perl code? by Umbral+Blot · · Score: 2, Interesting

      It is not that Perl is by nature less readable, however its community promotes values of terseness over readablility. For example when someone writes a quick perl script and posts it online, unless they were intending it to be used as a tutorial, far too many of the varaibles are one letter. Also Perl prgrammers tend to put more than one statment on a line by convention. While you can do this in C/C++ it is very rarely seen in the wild, unless somone is trying to be unreadable. So it's not the language, but some of its users.

    6. Re:Reading Perl code? by Phillup · · Score: 2, Insightful

      A language can encourage readability or discourage it. What does Perl do?

      Perl encourages writing code.

      It leaves readability as a lesson to be learned by the programmer when he has to fix his own bugs.

      If I added a "+++" operator to C that increments by two then I now have at least three (obvious) ways to increment by two. Does that mean that I can now be more creative in C?

      That depends, if you don't know the other two "obvious" ways... but you can easily remember the "new" way... then, yes. You are now more creative. Because now you have a tool you know how to use that will let you increment by two when you need to. The other two ways weren't much use to you, because you could not remember how to use them. (I'll leave discussion as to whether you should be programming if this is the case to another thread... that isn't the point)

      I think that is the part that people don't get about Perl. It isn't necessarily about the many, many ways to do a thing. It is about doing things in ways that are easy for the programmer to understand.

      By having many ways to do a thing, chances are, one will fit your thought process better than the others... and you'll have a tool you are comfortable with. Working with tools you are comfortable with... will make you more creative. Because you will spend your energy focusing on the problem, not on how to use your tool.

      --

      --Phillip

      Can you say BIRTH TAX
    7. Re:Reading Perl code? by Camel+Pilot · · Score: 2, Interesting

      As far as readability goes I find badly written perl easier to decode than badly written C or C++. Not sure why Perl acquired the reputation of being hard to maintain. I read other peoples perl code all the time and never really had a problem. On the other hand, I have spent days on a small section of C that had includes of includes and with heavy usage of global data. Having the ability to inspect the current scoped symbol table with a print Dumper(\%main::) or Dumper(%package::) is pretty cool.

    8. Re:Reading Perl code? by jdavidb · · Score: 3, Insightful

      If you think the Perl community describes the Obfuscation contests as an argument for the use of Perl, you are confused about who the community is.

      To me, the Perl community is that group of people that does promote readable Perl. Randal Schwartz is a part of that. There is a community out there of very good programmers who love Perl, and plugging into that community has been one of the best moves of my career. The people who actually invented and maintain Perl (Larry Wall, et al) are the real community, and they are very good programmers. The fact that there are a lot of other people out there knocking off quick scripts, running obfuscated contests, and writing ignorant books without reference to the accumulated wisdom of the real Perl community is not in any way a poor reflection on the Perl community and the Perl language.

      Yes, the good programmers of the Perl community do occasionally play a round of "Perl golf" or have an obfuscation contest. But noone worth his salt has ever put those forth as if it were a positive reason to use the language.

      Good programmers who use Perl use Perl because it is possible to write very good, high quality, modular, readable code in Perl. The people who actually create Perl exemplify and encourage this.

    9. Re:Reading Perl code? by ajs · · Score: 2, Interesting

      "Of course you can write some incredibly terse code in Python too, especially with recent language additions."

      Yep. EVERY language can be bent to horrid non-readability.

      If you want a language that enforces readability, I would suggest using Perl 6 (the first MAJOR step in the actual implementation of which was just made with the creation of a Haskell-hosted compiler called pugs) and writing a module which enforces your idea of readability. Perl 6 will be the first language to give you enough control that you can write this kind of requirement in the language itself. Common LISP comes in a close second, so use that in the mean-time if you want such levels of dictatorial control. Of course, you could write a module that allowed the rest of your program to be written in CL in P6 quite easily ;-)

      PS: y=x+++1 Guess what language that is. Answer: C, C++, Python and Java. Perl too if you just add $ before y and x. Programming languages are ugly.

    10. Re:Reading Perl code? by rs79 · · Score: 2, Insightful
      Warning: I'm grouchy. A CPU fan failed and let the smoke out of a new chip. I also discovered by accident Windows has a (320x240) television mode; it took me hours to unfuck somebody's PC.

      "And I would not include C in a list of languages for writing readable code in."

      I can understand how you can feel that way after looking at some of the C code that's out there. But you have to go out of your way to obfuscate C. There's a reason there's no obfuscated Perl contest: "everybody's a winner!".

      It's possible to write readable code in C. Not many people do it, I'll agree but this does not mean it cannot be done and you learn for your own beenfit, in time, to write very clear, lots of whitespace, one idea per line code. DMR's "one true brace style" is as much to blame for the obfuscation and unreadability IMO, as anything, and while he and I disagree on this, our understanding we've agreed to is as long as you can read and write both, that's ok. Keep in mind his justification is based on physical limitations of 24 line 80 column crts.
      if (thing == that){
      pritnf ("This sucks, Dennis.");
      }
      or
      if (thing == that)
      {
      printf ("My kids can understand this.");
      }
      C is a simple langauge with not that many operators, but it requires discilpine to write code you can go back to in 6 months or a year and still tell at a glance what it's doing.

      I also do not buy the "perl has more features" argument. If you need to do something often enough you write yourself a set of routines and use them as a black box library. My "web" one is 10 yrs old. Prior to that I carried around the same one for decades and with slight modes it worked from (real) Unix to CP/M to MS-DOS. Things got a bit fuzzy around the edges with Amiga and Windows GUI code, but they did not last long in my world. My one Windows gig was my last, it was too revoting to take seriously; I'm not into masochism.

      I would encourage aybody whose written a quick Perl hack to write it again in C as much for the learning experince as for the benefit of crusty farts like me who are sick of 7 levels of dependancies. Grabbing "the needed library" seems to be a recursive loop without end and I've given up many times trying to run some perl thing and found in most cases it's easier just to write it in C, which, once you're used to it you can do very very quickly. I will grant that it take a fair amount of time to overcome the learning curve but IMO it's absolutely worth it.

      To address the original point I have no problem with APL, Forth or Poscript. While they take a day to get used to, they're simple, fun and elegant. Parl just makes me hurt all over.

      At the risk of being permanently banned fom slashhdot forever I believe 1) Linux is more popular than BSD not because it's better in any sense, but because it's easier to install, and 2) Perl, similarly so, provides an instant gratification at a penalty of readability and to some extent, performance. I prefer "short term pain for long term gain" and shortcuts are just that. My grandmother said it best: "quality is the only economy".

      --
      Need Mercedes parts ?
    11. Re:Reading Perl code? by pileated · · Score: 2, Interesting

      Yes I think that's right. Perl gives you far more rope to write unreadable code with. And for some reason people delight in doing so. I really do think that it's part of the Perl culture.

      I'm sure I'm not alone in having spent a lot of time thinking about this over the years. I've recently had to both rewrite someone else's Perl code and write some new stuff of my own. What I noticed immediately is how easy it is to write something complicated in Perl and how easy it is to write code that is so terse that no one else will be able to understand it without considerable work. Worse I really think that the dominant Perl culture, as much as there is one, disdains comments and clear code in favor of terse and clever code. And Perl surely lets you do that.

      I should add that Perl is my primary language. But I also do a fair amount of Java coding and it sheds some interesting light on Perl. Yes it is incredibly verbose. But it also is much better about forcing you do consider error conditions. Perl by contrast allows you to THINK that you have a working program without informing you of the possible error conditions that exist. Yes I know about -w and use strict and they help. But not everyone uses them. As I said it's still my main language. But there sure are times when I liked to send it to Java school for a little discipline.

      On related matters I'd really recommend "Effective Perl Programming" by Joseph N. Hall, with Randall.

    12. Re:Reading Perl code? by jdavidb · · Score: 4, Informative
      • use Perl; is a good place, but very informal and tends to get sidetracked into politics :)
      • Your local Perl mongers group may be a great place
      • YAPC (Yet Another Perl Conference) and the Perl conference (now part of the Open Source conference) usually have many good presentations by the truly great Perl programmers
      • I have the impression that Perlmonks is pretty good, though I don't tend to use it much
      • Finally, the Perl5 Porters mailing list is the real original heart of the Perl community, though I think nowadays many of those guys have moved onto Perl6 work

      A list of names is also useful: material by Damian Conway, Larry Wall, Randal Schwartz, Mark Jason Dominus, Simon Cozens (Perl involvement now minimal due to career change), and persons associated with them is going to be top notch. Plug their names into Google and see what they have to say. Catch a presentation or read a book by one of them if you can. Meanwhile, there is truly a lot of junk out there. There's an article out there somewhere about "how to tell a good Perl book from a bad Perl book," which I thought was by Mark Jason Dominus, but I can't seem to find it at the moment.

      Finally, 90% of the useful modules you'll see recommended for use from CPAN are written by the intelligent lights in the Perl community. The time-tested modules that are now standard solutions are those that were written with high quality by good programmers.

    13. Re:Reading Perl code? by Anonymous Coward · · Score: 4, Insightful

      By having many ways to do a thing, chances are, one will fit your thought process better than the others... and you'll have a tool you are comfortable with.

      This speaks to the developer's experience, not the code maintainer's. The code maintainer is stuck maintaining code idioms not of his choosing: and the more idioms there are, the more idioms the maintainer needs to understand to maintain them all.

      Working with tools you are comfortable with... will make you more creative. Because you will spend your energy focusing on the problem, not on how to use your tool.

      Again, this balances developer comfort ("I get to choose the best fit of ten expressions! Woot! I'm so comfortable!") against maintainer comfort ( "I have to know ten different ways to maintain ten different developers code. Why can't they all just pick one! *grumble*").

      Maintaining someone else's code is usualy harder than writing your own, for the comfort factor you cited. A development culture that accepts esoteric ways to write code can be a nightmare, because the coder's defense is always There's More Than One Way To Do It.

      If there's One Way To Do It, and that's what the coder did, then I know exactly what it does. If there's One Way To Do It, and the coder didn't quite do that, then I've found a bug, or the coder wrote something subtle, and didn't comment it clearly. In either case, the fact that the code needs fixing stands out clearly.

      If There's More Than One Way To Do It, and what the coder did isn't clear, then I have to think hard to decipher what's going on, and whether it is what it appears to be, or whether it's some subtle little Perl trick.

      In short, TMTOWTDI helps developers, but at the expense of maintainers, and QA staff charged with proving code correctness.
      --
      AC

    14. Re:Reading Perl code? by niittyniemi · · Score: 2, Informative

      > I agree there is a problem in the community with stuff like this.
      > Personally, I tend to ignore the community and just use the language the way I feel it's best used.

      I started getting into Perl about 5 yrs ago and subscribed to comp.lang.perl.misc

      I have never come across a newsgroup inhabited by so many arseholes.

      The flaming of newbies was encouraged and posting obfuscated code par for the course. There was an overwhelming sense of how many Perl programmers thought themselves a cut above everybody else; full of people who would handily put obfuscated Perl in their sigs so that you could straightaway identify them as:

      (a) A language snob.
      (b) A fucktard.

      I unsubscribed from the group but persisted with Perl. For me, Perl fills the gap between shell scripts and pukka standalone apps (it's even pretty easy to GUIfy a script with Tk).

      I found the best resources to be the Camel book and Cookbook from O'Reilly.

      I bet a lot of people got put off Perl by that group at that time - God curse their black souls! It was a shame because there were some good contributions on the group from people like Randal.

      --
      The Machine stops.
    15. Re:Reading Perl code? by SilicaiMan · · Score: 3, Interesting
      If I added a "+++" operator to C that increments by two then I now have at least three (obvious) ways to increment by two. Does that mean that I can now be more creative in C?

      You give an extremely naive example. Even Perl doesn't allow you to do that ;-)

      But, consider this. Perl allows you to postfix your if() statements, like so:

      wave() if $person_seen eq 'Paul';
      This is much more naturally readable than:
      if ($person_seen eq 'Paul') { wave() }
      Similarly, you can use unless to make code easier to read:
      buy_food() unless you_forgot_your_wallet();
      This allows you to emphasize that buying food is the norm, and you would normally do it unless you forgot your wallet. The equivalent negative-if form does the exact same thing, but does not allow you to express your intent as well as this does.

      This is the essence of TMTOWTDI. You don't HAVE to use alternate ways to do things if you don't want to. But it does help most of the time in conveying your intent when you wrote the code, which make it more maintainable.

      Once I read someone comparing Perl to the human brain. The brain is a double-edged sword: it can compose the most pleasing melodies and most beautiful literature, but at the same time it can hatch evil plots of large-scale genocide and mass murder. Creativity has a dark side to it. Attempting to suppress that side will severly hinder the creative process. Same thing goes with Perl.

      I think Larry got it right.

    16. Re:Reading Perl code? by Chrax · · Score: 2, Insightful

      I more or less learned perl and C cotemporaneously, so I see where you're coming from. But really, once you get over the idea of no real data types, and learn a couple of the tricks perl does in order to drop extra variables, it's not a big deal, and I think it's time well spent learning.

      And while yes, Java is easy to understand, it's just another step in the C line that, in the end, doesn't allow for the flexibility of perl, or rather can't be both as flexible and compact as perl.

    17. Re:Reading Perl code? by ajs · · Score: 4, Informative

      "A complex list comprehension can lead to some powerful code that does an amazing amount of stuff in a neat little package. To me this is different than the arbitrary line-noise you get with Perl."

      There you just lost me. The term "line noise" implies a low signal-to-noise ratio, when in fact Perl presents exactly the opposite. The SIGNAL is in fact, so high that many programmers find it difficult to cope with. That's fine, but let's not confuse that with actuall NOISE.

      "So Perl 6 lets you define your own syntax so that someone reading your code neads to figure out what your ideas of the Right Language is?"

      No. You wholy misunderstood the concept.

      In Perl 6, you will have full access to the grammar, so you could enforce your local stylistic conventions. You would obviously not want to make INCOMPATIBLE changes so that your code is still valid Perl, but you could write your own "strict".

      Think of it this way. Imagine a C++ header that caused all uses of operator overloading outside of a limited few "neccessary" to be illegal, or that issued a compiler warning on every use of an iterator initialization outside of a for loop. These are just simple (and not very useful) examples, but they serve to illustrate the point: you can instrument the compiler just as fully as you can instrument your code. Don't like the type checking in Perl 6? Make it stricter.

      I'm sure that there will be someone who will publish the "python-like bondage" module 15 minutes after Perl 6 is released. If you're into that sort of thing, then your company can take full advantage of it, while still getting all the value of Perl 6 like LISP-style currying and macros, Ruby-style mixins, cross-langauge bindings through Parrot, boxed and unboxed type constraints on standard Perl scalars, full multi-method dispatch, etc., etc.

      "Common LISP and Scheme's macro facilities can be used to define your own language constructs"

      Yes, but we're not talking about defining language constructs. We're talking about changing the behavior of the compiler in structured, standardized ways that aren't just implementation hacks. Don't get me wrong. Common LISP is on my list of cool languages to learn more about right below Python and Ruby. I'm just saying that these particular Perl 6 features bear a bit more looking at.

      "Or hell, TeX lets you redefine the world if you are so twisted, though to me TeX is more unreadable than Perl."

      TeX is actually a good example of what I'm talking about. TeX is very readable for a full typesetting system, but most of us could not care less about typesetting. When you need to do specific tasks that INVOLVE typesetting, but you don't really need all of that power and flexibility, you step up a layer of abstraction and turn TeX into LaTeX. LaTeX is valid TeX, so it's not quite the same, but the idea of limiting a powerful system in order to step back a level of abstraction holds.

      Perl 6 will provide all of the power that you need from a modern high-level programming langauge, but let you manage that complexity. You might decide, for example, to restrict Perl 6 in your programs to just the facilities that make sense for scientific calculation. You might even introduce a special syntax/grammar for putting differential equations directly into your program without having to quote around them and hand them off to a seperate processing tool (object, module, what-have-you).

      None of this is useful for your average 1000-line CGI program, but for the company that produces tens to millions of lines of structured libraries upon which new software is built and re-factored over time, this will all be a godsend.

      Much of what Perl 6 brings to the table, Common LISP has done for years, but some of it is either gathered from other, more recent langauges (e.g. Python, Ruby, Scheme, Java, etc.) or is, as far as I can tell, unique. I hope you give it a try and throw away your naive ideas of "line noise" in favor of considering the value to your productivity and the maintainability of your code base.

    18. Re:Reading Perl code? by rs79 · · Score: 2, Interesting

      "...Mark Jason Dominus..."

      Oh shit now I know I'm old. I see that name and "Perl" dosn't even come to mine. talk.bizarre does.

      --
      Need Mercedes parts ?
    19. Re:Reading Perl code? by SimHacker · · Score: 2, Insightful
      "Don't get me wrong. Common LISP is on my list of cool languages to learn more about right below Python and Ruby."

      Please, work your way a little bit further down that "list of cool languages to learn more about", before telling people they should use Perl.

      --
      Take a look and feel free: http://www.PieMenu.com
  4. Hooray! by Kimos · · Score: 2, Funny

    Another punny title!!

  5. $subject by Anonymous Coward · · Score: 3, Funny

    I really $feeling $author. His contributions to $language were $adverb $adjective. I really hope he $does_doesnt[int rand(1)] write more books. The are $adverb2 $adjective2.

  6. Tip #1... by MoeDrippins · · Score: 5, Funny
    --
    Before you design for reuse, make sure to design it for use.
  7. learning languages by bungley · · Score: 3, Insightful
    In my opinion, the best way to learn any language well is to see how others have used it to solve problems.
    Strange, everyone else I've spoken to EVER has said the best way to learn a language is through practice. Then again, I suck at programming.
  8. Perl doesn't kill readability... by jqh1 · · Score: 5, Insightful

    People kill readability (with Perl).

    Seriously, choose the right tool for the job. When we've got a sys-admin level scripting task, and someone can go in and knock it out in a half hour (or less) with a few lines of Perl, who can say that's bad? I'm currently wading through a bunch of heavily patternized java that pulls checkin logs from a scm system and updates an issue tracking system as part of the build process. It's taken me *days* to begin to "grok" what's going on in the many associated xml config files and bizarre string handling approaches that were used in this undocumented hack. I'll replace it with probably less than 150 lines of Perl, and someone else will happily (and much more easily) maintain it. So there!

    At the same time, we've got > 25 developers distributed around the world working on a big commodities trading app -- java works pretty well for that.

    --
    who's moderating the meta-moderators?
    1. Re:Perl doesn't kill readability... by m50d · · Score: 3, Insightful

      Yes, but perl is a hair-trigger for you. Obfustucating C or Java takes a bit of effort. Obfustucating Python is pretty hard, your best bet is to lambda over everything and hope the reader isn't a primarily lisp programmer. Obfustucating perl can be done without thinking. Seriously, perl is a tool for quick scripts that will be rewritten rather than edited. It's designed for things which take up less than one page of code to write. It's fast to write short programs, but you should think again before writing a big one in perl, maybe try and chain some small ones together instead.

      --
      I am trolling
    2. Re:Perl doesn't kill readability... by ajs · · Score: 5, Interesting
      "People kill readability (with Perl)."

      As they do with C, C++, Java, Snobol, Forth, APL, C#, etc, etc.

      Half of the people programming are below-average programmers. Bad programmers can make life HELL in C, and by the same token good programmers can make life quite easy in Perl.

      That said, Perl gets a bad rep, not because good code is hard to read, but because a) bad code is more common in any language which is easy to learn and b) Perl has several features which people mistake for non-readability (that is, non- or inexperienced Perl programmers assume that code is hard to read because they don't know Perl and see these things which scare them):

      • Regular expressions - This is a common feature in almost all languages these days, but the ease with which they are integrated into Perl syntax makes them more common in Perl programs. Of course, you have to be careful about the amount to which you let such constructs take over your code, but Perl was the one to introduce whitespace formatting and comments into regular expressions for just this reason.
      • Typing glyphs - Many programmers from the C/Pascal/Fortran - derived world take exception to the prefix-characters in Perl. Some Perl programmers find it hard to read C code that uses subroutines, complex data structures and simple types without any indication of what's being accesed or how. It's a matter of time and exposure on BOTH sides, and being a programmer in both worlds, I can tell you that both are equally readable with sufficient exposure.
      • Context sensitivity - Perl's context sensitivity spans every level from the way the tokenizer works all the way up to the handling of large-scale data structures. This is the nature of a language designed by a linguist. It "reads well", but only when you start trying to read it like a spoken language, and not a mathematical code. Software source code has always been somewhere in the middle-ground between those two extremes, and it's jarring at first that Perl moved the line so much, but give it a while and you find that it's much easier to think and communicate complex ideas (by complex, I mean cognitive complexity, not code complexity) in Perl than in any other programming language.
      • Weak typing - This is a matter of religion, but I'll make a footnote of it anyway: Perl is weakly typed, and that frustrates many who are used to strong typing. Neither is better or worse, though the fact that Perl 6 will (as Common LISP has done for quite some time) give you both is a boon, I think.

    3. Re:Perl doesn't kill readability... by moof1138 · · Score: 3, Insightful

      I have had to deal with a lot of Perl, Java, and PHP. The nastiest ugliest code I ever inherited was PHP. I agree that Python tends to be more readable since it has a more limited... expressiveness... than Perl, but PHP with it's endless heap of little functions that do nearly the same thing and its oddly inconsistent namespace can mutate as readily as Perl, especially when wielded by an inexperienced programmer.

      --

      Hyperbole is the worst thing ever.
    4. Re:Perl doesn't kill readability... by Fahrenheit+450 · · Score: 2, Insightful

      Regular expressions - This is a common feature in almost all languages these days, but the ease with which they are integrated into Perl syntax makes them more common in Perl programs.

      And this is exacerbated when people pull out all sorts of jiu-jitsu to apply regexes to problems that are better and more cleanly handled with a general purpose lexer. But I can see where pulling out a lex-alike doesn't work too well when you're dashing off a script.

      Perl is weakly typed, and that frustrates many who are used to strong typing.

      Actually this isn't quite right. [confession_mode=on]A couple of weeks back I ranted a bit about this and the whole "a number is a string is a boolean..." nature of Perl and how this implied weak typing. Well after thinking about it for a while, I realized that Perl is actually strongly typed with respect to its (fairly unconventional) type system. The fact that the type system is so unusual is what troubles most people (myself included).[confession_mode=off]

      --
      -30-
    5. Re:Perl doesn't kill readability... by merlyn · · Score: 2, Insightful
      There are messy desk people, and clean desk people. If you force someone who normally works with a messy desk to have a clean desk, their productivity goes down. Likewise in reverse.

      Similarly, there are Perl people, and there are Python people. One is not better than the other. It just matters on a manner of fitting.

      Please stop with the "one is better than the other" stuff. Better for you perhaps.

  9. TIMTOWTDI acronym expanded by PornMaster · · Score: 3, Informative

    For those trying to follow along but not able to immediately expand the acronym, TIMTOWTDI is There Is More Than One Way To Do It.

  10. perlmonks by Porag_Spliffing · · Score: 4, Informative

    For anyone getting into perl I can not recomend The Perl Monks Monastery enough. Lurk for a while, use super search to find the answers to almost any perl question you may have and if all else fails post to Seakers Of Perl Wisdom and enlightenment shall surely follow.

    Randal is a regular contributor there and many of the other leading lights of perl pop up frequently.

    Regards,
    A monk.

    --
    Maybe you live in interesting times
  11. IMPOSTER!!! by MisterLawyer · · Score: 2, Informative

    Randal Schwartz's Perls of Wisdom will never take the place in my heart that is forever occupied by Steve Litt's PERLS of Wisdom!

  12. Re:Perl and work by gurps_npc · · Score: 5, Insightful
    You made an error that I think a lot of people make.

    It is not how long it takes you to understand a perl script of X length that is relevant.

    What SHOULD be the important data is: Whether it would take you MORE time to understand a C or Java program that does the same thing.

    I have seen cases where people complain that it takes them a week to understand a Perl Script of 500 lines. So they write a new program in C, that does the same thing in 5,000 lines. Which then takes me 8 days to understand.

    One of Perl's image problems is that because it does so much with so little, people underestimate what the tiny program does and therefore get frustrated when it takes them more time to understand than a C program of the same size, even though the C program does 1/10 what the Perl one does.

    --
    excitingthingstodo.blogspot.com
  13. Dear Mr review writer... by rjshields · · Score: 4, Informative
    my ($f) = 'fortune';
    Should use back ticks instead of single quotes like so:
    my ($f) = `fortune`;
    Otherwise you assign the string "fortune" rather than the output of the fortune program ;)
    --
    In this world nothing is certain but death, taxes and flawed car analogies.
  14. Schwartzian Transforms and raised hackles... by Fahrenheit+450 · · Score: 3, Informative

    Randal also discusses formatting and the nifty "Schwartzian Transform" (Perl's map-sort-map idiom for sorting on almost anything) which was named for him, but not by him.

    This is one of the things that's always annoyed me about Perl and its practitioners (well, most programmers, really)...

    Given the long history of functional programming (hell, Lisp is closing in on 50 years old), this map/sort/map idiom had to be second nature to any Lisp/Scheme/Haskell/ML/etc. programmer at the time Schwartz wrote about it back in 1996[1]. And the fact that this was such a revelation to the people who read his column that they named the idiom after him just exposes the lack of a diverse programming background for most people. I'm guessing that 50% of the coders out there wouldn't know a map or a fold if it bit them on the ass, and even more wouldn't have a clue as to how to solve something so basic as the missionaries and cannibals problem in a declarative/logical manner (without the help of Dr. Google that is).

    Meh... Bitter rant over, I guess...

    [1] I could be wrong, I didn't really do much coding before 1995-ish.

    --
    -30-
    1. Re:Schwartzian Transforms and raised hackles... by merlyn · · Score: 4, Informative
      I've actually said your exact point a number of times. In fact, I didn't "invent" anything. I was solving someone's problem, who had posed the problem in the Perl newsgroup, using the knowledge I had at hand. As I'm also a LISP hacker (see my "pretty printer" in the GNU Emacs distribution), I simply relied on my knowledge of simple list manipulation techniques to transform the problem into something workable.

      I had no idea it would take on a life of its own as a standard idiom. And it was not originally "for a column". It was a usenet posting and wasn't presented as anything remarkable.

      Just trying to set the record straight.

    2. Re:Schwartzian Transforms and raised hackles... by Fahrenheit+450 · · Score: 2, Interesting

      Just trying to set the record straight.

      Oh, don't worry, I'm not blaming you or calling you out or anything like that. Hell that column at the least opened a few eyes, and that's a good thing. It's just that the ST term is one of the triggers that set off some variant of a bitter "programmers need to learn more paradigms/languages" rant in me...

      And the voices in my head won't go away until I vent it somehow...

      --
      -30-
  15. My Sig Says It All by frank_adrian314159 · · Score: 3, Funny

    You don't learn Perl - it gets absorbed through the blood-brain barrier. Leads to nasty flashbacks, too...

    --
    That is all.
  16. Re:Not an acronym! by That's+Unpossible! · · Score: 2, Informative

    It's not an acronym or a retro-nym. It's a name, Perl. It started as Gloria (after his wife) before it was released, then it was Pearl, then he released it as Perl.

    In the old days people spelled it in all caps, i.e. PERL, which was probably due to the fact that people (including Larry) like to pretend it stands for something. I am not aware of any O'Reilly books that refer to it as PERL, they all list it as Perl.

    The most common acronym attributed to it is "Practical Reporting And Extraction Language."

    (You'll note that actually spells PEARL, a hint of its early name.)

    If all is right with the world, Tom Christiansen will flame me unmercifully with everything I got wrong in the preceding story.

    JASP - Just Another Slashdot Poster

    --
    Ironically, the word ironically is often used incorrectly.
  17. Learn to program by PhiznTRG · · Score: 2, Funny
    In my opinion, the best way to learn any language well is to see how others have used it to solve problems.

    Why of course! It worked for Bill Gates, it can work for you too!

    "The best way to prepare [to be a programmer] is to write programs, and to study great programs that other people have written. In my case, I went to the garbage cans at the Computer Science Center and fished out listings of their operating system."
    From Wikiquote.
  18. Re:Perl and work by bani · · Score: 3, Insightful

    that's part of the problem with perl -- the code is often incredibly terse and dense.

    you can do incredibly complex things in a few characters in perl, which can be far more difficult to grok than the same thing described in 20 lines of C code.

    it's both a blessing and a curse. a blessing because you can beat out very complex things quickly, and a curse because it is a major pita to maintain.

    perl also stubbornly avoids some useful language constructs in the name of "language purity". eg case statements. yes i know about Case.pm, but its not stock perl. and yes i know perl6 will have it. only took them ~20 years to get there :-P

  19. Re:Not an acronym! by That's+Unpossible! · · Score: 2, Informative

    The most common acronym attributed to it is "Practical Reporting And Extraction Language."

    (You'll note that actually spells PEARL, a hint of its early name.)


    Who needs Tom C., I'll just flame myself.

    Actually it spells PRAEL. Duh, I got the wording twisted, it's obviously Practical Extraction and Reporting Language.

    Also, I am wrong about the use of PERL on O'Reilly books. I am surprised to see the PERL in a Nutshell title from O'Reilly.

    And as a twist on the theme, the pink camel book actually is called "Programming perl," with "perl" in all lowercase.

    --
    Ironically, the word ironically is often used incorrectly.
  20. Re:Quote by merlyn · · Score: 2, Informative

    False quote. Wheee.

  21. About 'my ($f) = `fortune`;' by Shachaf · · Score: 4, Informative

    Read more about the issue here.

  22. Re:Perl and work by m50d · · Score: 2, Insightful

    It still takes more effort for me compared to python. Not compared to C, but C takes lots of instructions to do simple things - use only when necessary. And I think the problem is that the syntax is so different. You throw a c/java/python/etc. program at a programmer from another language and they'll get the basic idea. They'll be able to see where the functions are, how the control flow goes, with a little bit of effort what the variables are. You throw a perl script at someone who hasn't seen perl, and a few are alright, but most look like so much line noise. You have to relearn a lot of your programming knowledge, and if perl isn't your only language then you have to switch modes when you see it. If I could program with it all the time, it would be good, but the fact is I have to use C and Java a lot of the time, so I need a language which isn't too different from them.

    --
    I am trolling
  23. Its not the language... by psicode · · Score: 2, Insightful

    its the developer that writes unmaintainable code.
    TMTOWTDI and the Perl syntax have hardly anything to do with badly written code in Perl or any other language. Sure understanding an expressive language like Perl takes a bit more than learning a language like Java. But that does not mean that Java or [insert any language here] prevents you from writing ugly code. I am primarily working as a Java developer on mostly large projects and the amount of badly written code I have to deal with is simply frustrating. And most of it is written by "Senior" developers and design pattern aficionados!!!

  24. Re:Perl and work by Kismet · · Score: 2, Interesting

    While I think yours is a fair assessment, there is one other aspect that needs to be emphasized:

    Perl syntax is very flexible. You can write Perl that looks something like C, or Perl that looks something like Basic, or Perl that looks something like Java, etc.

    You might get two Perl programmers who both write small, efficient programs to do the same thing using similar architectural and design approaches. Both programs could look radically different, depending on the author's slant on Perl.

    That is what makes reading Perl difficult.

  25. Re:Perl and work by John+Bokma · · Score: 2, Insightful
    Well written, and agreed. instead of: s/foo/bar/i; people somehow prefer:
    private RegExpThingy re = new RegExpThingy;
    try {
    re.compileASearchAndReplaceCaseInsensitiveThingy( "foo", "bar" );
    re.doDaSmartThingyOnAStringy( sumvar);

    } catch RegExpCompilingFUBARException {
    /* ignore it */
    }
    I wonder why... the days one got 0.10 USD a line are over, or not?
  26. It's easy! by fprog26 · · Score: 2, Insightful

    It's not difficult to read at all; however, you wrote it in backward perl syntax with implicit variables. It's easy. It prints a concatenated list of prime numbers between 2 and 100 with no delimiter.

    So, let's rewrite this program without implicit $_ variable, without && comparision and with a temporary variable.

    for my $number (2..100)
    {
    my $unary_string = (1 x $number);

    if ( $unary_string !~ m/^(11+)\1+$/ )
    {
    print $number;
    }
    }

    Which is quite readable now.

    For all numbers between 2 and 100. Take that number convert it into UNARY format. Now, if it doesn't match recursively the first set of ones (at least 2) with the trailling set of ones having the same number of ones (at least once).

    So basically the matching algorithm is like this:

    2 11 insufficient
    3 111 insufficient
    4 11 11 matched 4
    5 11 1 11 mismatch
    6 111 111 matched 6
    7 111 1 111 mismatch
    8 1111 1111 matched 8
    9 111 111 111 matched 9
    10 11111 11111 matched 10
    11 11111 1 11111 mismatch

    It seems to test for prime numbers...

    If it's not a non-prime number since no match is found it prints the number without any delimiter on stdout.

    Conclusion:

    If I was to write this script with this "algorithm", I would write it like this:

    #!/usr/bin/perl -w

    # Print prime numbers between 2 and 100 by converting it into unary format and by testing for matching multiple pairs of double ones or more.

    for (2..100)
    {
    my $unary_string = (1 x $_);

    print if ( $unary_string !~ m/^(11+)\1+$/ );
    }

    BTW, writing a program in C to test for prime number would be quite more complicated!
    Especially if you use this algorithm without a regexp library!

    Enjoy!

    Fred.

    - Long life to Perl!

  27. Re:Perl and work by kneeless · · Score: 2, Insightful
    perl also stubbornly avoids some useful language constructs in the name of "language purity". eg case statements. yes i know about Case.pm, but its not stock perl. and yes i know perl6 will have it. only took them ~20 years to get there :-P
    From the Camel:

    Unlike some other programming languages, Perl has no offical switch or case statement. That's because Perl doesn't need one, having many ways to the same thing. A bare block is particularly convenient for doing case structures. Here's one
    SWITCH: {
    (!$whatever) && do { &go("yes"); last SWITCH; }
    ($something) && do { &go("no"); last SWITCH; }
    ($nothing) && do { &go("???"); last SWITCH; }
    $somethingelse = 1;
    }
    After this, there are four other examples showing this in more ways. Go get the Camel, it's invaluable.
  28. Re:Not an acronym! by teknomage1 · · Score: 5, Informative
    From perlfaq

    What's the difference between "perl" and "Perl"?

    One bit.

    Oh, you weren't talking ASCII? :-) Larry now uses "Perl" to signify the language proper and "perl" the implementation of it, i.e. the current interpreter. Hence Tom's quip that "Nothing but perl can parse Perl." You may or may not choose to follow this usage. For example, parallelism means "awk and perl" and "Python and Perl" look OK, while "awk and Perl" and "Python and perl" do not. But never write "PERL", because perl is not an acronym, apocryphal folklore and post- facto expansions notwithstanding.

    --
    Stop intellectual property from infringing on me
  29. I like Perl by Cyno · · Score: 3, Insightful

    I wrote a Perl script yesterday with a bad algorithm using 2 lists. Ran all night and was still running when I got into the office this morning, and it didn't spit out any relevant data.

    Rewrote the script using 2 hashes in about 15 minutes. Completed in less than a minute with all the info I was looking for.

    So, um, I think an evaluation of most programming languages is more dependant on the programmers than the language itself. Sure some languages lack the proper data types or features, but any modern/complete language is capable of being readable and resource efficient if the programmer knows what they are doing. IMO, of course. I'm not a developer.

  30. Re:Perl and work by rs79 · · Score: 2, Funny

    "Care to explain this?"

    Easily. A young white male who had taken too much caffeine smoked a joint at 4 am to calm down at on a project that was way overdue and underfunded had to add several things to his code to make it work by trying them at random; eventually it worked but he can't explain why.

    How'd you get access to the MX missile codebase just out of curiosity?

    --
    Need Mercedes parts ?
  31. Re:Perl Is Awesome by rs79 · · Score: 2, Funny

    " I have yet to come across a task that couldn't be implemented fairly easily in Perl."

    Write all of Unix from scratch on a PDP 11/20.

    I'll wait.

    --
    Need Mercedes parts ?