Slashdot Mirror


Pro Perl Debugging

Michael J. Ross writes "The typical computer program has more bugs than there are ants at a picnic -- except ants are usually easier to find. Programs written in Perl are no exception, because the compactness of the language does not make any existent bugs easier to spot; they can simply be packed into fewer lines of code. To help remedy this problem, Richard Foley and Andy Lester, two seasoned Perl programmers, offer a new book, Pro Perl Debugging: From Professional to Expert." Read the rest of Michael's review. Pro Perl Debugging: From Professional to Expert author Richard Foley with Andy Lester pages 269 publisher Apress rating 8 reviewer Michael J. Ross ISBN 1590594541 summary A comprehensive tutorial and reference for the Perl debugger

This title was published in hardcover in March 2005 by Apress, a relatively new member of the technical publishing world. The publisher has a Web page for the book that includes links to all of the source code in a Zip file, the table of contents in PDF format, and a form for submitting errata. The book comprises 269 pages, the majority of which are organized into 16 chapters: Introduction (not to be confused with the true Introduction immediately preceding it), Inspecting Variables and Getting Help, Controlling Program Execution, Debugging a Simple Command Line Program, Tracing Execution, Debugging Modules, Debugging Object-Oriented Perl, Using the Debugger As a Shell, Debugging a CGI Program, Perl Threads and Forked Processes, Debugging Regular Expressions, Debugger Customization, Optimization and Performance Hints and Tips, Command Line and GUI Debuggers, Comprehensive Command Reference, Book References and URLs.

For programmers who wish to learn how to fully utilize Perl's debugger, what options are open to them? A terse summary of the debugger's commands are always close by, within the debugger itself. Those Perl coders who have yet to try the built-in Perl debugger, really owe it to themselves to give it a whirl. In most cases, it is superior to embedding lots of "print" statements in your scripts, and then wading through the results. Simply include perl.exe's -d flag on the system command line, and you should be put right into the debugger, and see the debugger's "DB<1>" command prompt -- the "1" meaning that it is ready for your first command. To display the aforementioned command summary, simply enter "h", or "|h" to see the output one screen-ful at a time, which you will probably want to do unless your system window can show all of the dozens of lines at once. The command summary is best used as a quick reference, and naturally cannot be expected to serve as any sort of tutorial. Yet it has its use, and for that, it's fine.

Most Perl books devote at least some space to explaining the basics of firing up and using Perl's debugger. The (in)famous "camel book," Larry Wall's Programming Perl, has a chapter on the debugger. It covers breakpoints, running, stepping, tracing, displaying code, commands, debugger customization, debugger options, unattended execution, creating your own debugger, and performance profiling. Aside from that last topic, the chapter is mostly an expansion of the command summary mentioned earlier. It is sparse on examples, and does not cover any advanced topics, such as using the debugger in the context of forking, threads, and POE, as well as the debugger's special capabilities for regular expressions, CGI programs, and shelling out.

The advanced topics are where Pro Perl Debugging really shines in relation to the coverage that I have seen in any other book, partly because the authors have the space to thoroughly explore those topics in depth, and to provide much more meaty examples, with adequately illustrative sample code. Even for the more complex topics, the writing is clear, and the examples are worthwhile.

The authors clearly intend for the book to serve as both a comprehensive tutorial and a reference for the Perl debugger. In both respects, they succeed admirably. But the practical value of their accomplishment could be called into question by any programmer who has grown tired of the limitations of the Perl debugger, and has switched over to any Perl-capable standalone GUI debugger or integrated development environment (IDE). More specifically, watching a variable change value, while stepping through the lines of a Perl script using the debugger, requires that the programmer manually or programmatically echo that variable's value, by issuing a print command ("p") followed by the variable name, one way or another. This process quickly becomes tedious when multiple variables need to be watched, because each individual variable must be printed, one at a time. Admittedly, previously entered print statements can be recalled by using the up-arrow key, but only if the particular command has not been pushed out of the debugger's limited storage. This usually becomes even more frustrating when trying to print the values of indexed arrays, hashes, and nested arrays and other structures. There are workarounds, but none are pretty, and even the most promising techniques still seem to require excessive focusing on the debugger commands themselves, drawing attention away from the code being debugged.

As a result, some disheartened Perl coders eventually switch back to embedding "print" statements in their code. Fortunately, there is a better alternative, in the form of IDEs, which can automatically report the changing values of a large set of variables, none of which need to be typed in, owing to the drag-and-drop capabilities of most IDEs. There are many IDEs available, including freeware and open source offerings. Most if not all of them support advanced editing, syntax highlighting and verification, visual breakpoints, and other much-appreciated capabilities. Even if they were to lack all of these features, and only have the advantage of easily and dynamically displaying the current values of variables, then they would be much more pleasant to use than the built-in Perl debugger. This is especially true in the case of nested structures, which can be expanded with a mouse click within most IDEs. All of this being said, it should be noted that the authors include a chapter that briefly touches upon the most well-known Perl GUI debuggers -- but at only seven pages in length, the chosen applications get only a cursory treatment, highlighting their major features.

Nonetheless, given the intended purpose of Pro Perl Debugging, and its target audience, the book cannot be faulted for its contents nor its approach to presenting the material. Anyone looking for a detailed and competent explication of the native Perl debugger, would likely not be able to find a more thorough treatment anywhere else.

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

You can purchase Pro Perl Debugging from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

164 comments

  1. I luv Perl, but... by Orrin+Bloquy · · Score: 1

    ...there's something about an interpreted language which can be optimized down to nearly the size of machine code, only less readable.

    --
    "Made up/misattributed quote that makes me look smart. I am on /. and I must look smart."
    1. Re:I luv Perl, but... by winkydink · · Score: 4, Insightful

      IMHO, that says more about the programmer than the language.

      --

      "I'd rather be a lightning rod than a seismometer." -Ken Kesey

    2. Re:I luv Perl, but... by digitaldc · · Score: 1

      ...optimized down to nearly the size of machine code, only less readable.

      But isn't that the point of writing your own code?

      --
      He who knows best knows how little he knows. - Thomas Jefferson
    3. Re:I luv Perl, but... by Phroggy · · Score: 1

      What? All perl code is perfectly readable! ;-)

      What do you mean by "optimized down to nearly the size of machine code" though? I'm not sure what you're talking about.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    4. Re:I luv Perl, but... by tomhudson · · Score: 0
      ..there's something about an interpreted language which can be optimized down to nearly the size of machine code, only less readable.
      Big deal. You still need to lead the interpreter, and set up the host environment, etc. Besides, the best way to debug a perl program is to rewrite it in python.

      I've been using perl for years, but I'm dumping it for most things.

      It took me less time to learn python and write my first utility (a page generator for 195 content categories in2 languages from source data files) than it would have to write it in perl and debug it.

      The whole "TMTOWTDI" is just wrong, from a maintainability point of view. If you can't maintain it, you can't really reuse it.

      And perl's greediness in matching strings sucks (because someone was too lazy to put proper string functions into the language?)

      Perl - because when it all looks like line noise, nobody can criticize the "quality" of your code.

    5. Re:I luv Perl, but... by el-spectre · · Score: 2, Interesting

      And perl's greediness in matching strings sucks (because someone was too lazy to put proper string functions into the language?)

      Hey, just cuz you can't write a decent regex...

      --
      "Faith: Belief without evidence in what is told by one who speaks without knowledge, of things without parallel." - A.B.
    6. Re:I luv Perl, but... by jonadab · · Score: 2, Interesting

      > It took me less time to learn python and write my first utility
      > (a page generator for 195 content categories in2 languages from
      > source data files) than it would have to write it in perl and
      > debug it.

      *shrug*. Maybe you just think Guido's Way. Some of us don't. I tried to learn Python, but every time I tried to do anything in it, I ran into frustrating scenarios wherein I'd need to write eighty lines of code just to do something really simple. Maybe it's because I didn't know Python well enough yet to write it compactly, but whatever the reason, I just couldn't make myself finish learning the language.

      In any case, a page generator for 195 content categories in two langauges from source data files sounds more like a round of golf; if it were an actual programming task, 80% of the time would be spent deciding which three modules to use (for parsing the source data, for generating the content's form, and for the language issue), and writing the code to put it all together would be 5%. (Allow 2-3% for debugging, and the rest of the time would go into writing the documentation.) Sounds *much* easier than learning a new language. (The *fastest* I ever learned a programming language to my satisfaction (discounting data languages such as SQL) was two weeks, and I spent twice that long attempting to learn Python... there's absolutely no way writing the page generator you describe could take that long.)

      > The whole "TMTOWTDI" is just wrong, from a maintainability point of view.

      Why? Why does it make the code less maintainable to solve each problem in the way that is natural to solve that problem, rather than trying to coerce every problem into a particular paradigm that may or may not be a natural fit for the problem? The best feature of Perl is its multiparadigmatic nature, that allows the programmer to select the best type of solution for any given problem. (Well, okay, maybe the *best* feature is the CPAN, but the multiparadigmaticity is a close second.)

      I find that well-written Perl code is much more maintainable than code in most other languages. (Poorly-written Perl code is, of course, completely unmaintainable, but it's possible to write unmaintainable code in any language.)

      > And perl's greediness in matching strings

      Umm, did you read the documentation? If you want non-greedy matching, that's easy enough to do. The really handy things, though, are lookahead and lookbehind assertions. I just wish we could get variable-width lookbehind; presumably Perl6 will make this possible.

      > Perl - because when it all looks like line noise, nobody can
      > criticize the "quality" of your code.

      If it all looks like line noise, the code doesn't *have* any quality.

      --
      Cut that out, or I will ship you to Norilsk in a box.
    7. Re:I luv Perl, but... by tomhudson · · Score: 1

      (The *fastest* I ever learned a programming language to my satisfaction (discounting data languages such as SQL) was two weeks, and I spent twice that long attempting to learn Python... there's absolutely no way writing the page generator you describe could take that long.)
      Learning enough python to do the job took less than an hour.

      If you already have a decent background in c and at least one scripting language, say php, you should be good to go.

      The hardest part? I kept putting in semicolons.

      There's no way it should take 2 weeks to learn how to open files and use python's re module and data structures, especially since the data structures all have perl analogs.

      Perhaps you had the wrong book? Or were not motivated enough? Anyone with programming experience (even BASIC) should be able to learn python in a day.

    8. Re:I luv Perl, but... by patio11 · · Score: 1

      True, but computer languages are not just the bits you learn in the language reference. There is also a culture surrounding each computer language, because eventually much code has to be seen by another geek versed in the language. And the culture surrounding Perl is the computer language equivalent of an island of cannibals. There are some wonderful pieces of native art if you can get past that whole spear-you-and-eat-your-brains thing. Perl programmers seem to take a perverse enjoyment in making the reader of their code suffer because the ability to do that is a mark of status in the perl community. Compare it to the way that C++ programmers are obsessive about speed/memory constraints even when its not warranted by the task at hand or the way you can't talk to a Java programmer without him immediately starting to see visions of a class hierarchy.

    9. Re:I luv Perl, but... by Metasquares · · Score: 1
      .*? - Now you'll get a lazy match.

      Or just use something like [^>] (if you're looking for a closing angle bracket to end a phrase).

    10. Re:I luv Perl, but... by tomhudson · · Score: 1

      There's no replacement for proper string functions and an intuitive regular expression engine. And no excuse not to have them. Larry Wall made a mistake there, and its been perpetuated in the name of "backwards compatabiity" ever since.

    11. Re:I luv Perl, but... by Anonymous Coward · · Score: 0

      There's no replacement for learning how to use real regular expressions.

    12. Re:I luv Perl, but... by andy@petdance.com · · Score: 1

      What "proper string functions" are you missing that you would like?

    13. Re:I luv Perl, but... by Anonymous Coward · · Score: 0

      Knowing perl, it tells me more about him than about perl - it tells me he's Perl's Mum!

    14. Re:I luv Perl, but... by el-spectre · · Score: 1

      "Intuitive" pattern matching? say what?

      What do you want, $x matches a_letter_between_a_and_z or something?

      There's a reason lot of languages have adopted the Perl regex rules (which were in turn based on earlier Unix programs). Don't blame your failure to understand the technology ON the technology when millions of us do just fine.

      Those that decry the complexity of regexes often have yet to realize how powerful they are, when used correctly.

      --
      "Faith: Belief without evidence in what is told by one who speaks without knowledge, of things without parallel." - A.B.
    15. Re:I luv Perl, but... by tomhudson · · Score: 1
      What I want:

      1. better defaults. Wall screwed up. Get over it.
      2. proper string functions
      3. no more silent conversions between 0 and null and '0' and '' - that's stupid

      Oh, wait - its easier to just rewrite the damn thing in pretty much ANY other language. Its not a question of understanding it - its a question of maintainability. Isn't that what debugging is about 90% of the time - fixing bugs that creep in because code is, in fact, NOT maintainable?

    16. Re:I luv Perl, but... by el-spectre · · Score: 1

      1) "what you like" != better
      2) learn to use the language
      3) No, it's intentional.

      What language zealots (of ANY language) fail to realize is that there are different styles of coding for different uses and different users. Insisting that there is ONE TRUE WAY to program isn't a sign of wisdom...

      --
      "Faith: Belief without evidence in what is told by one who speaks without knowledge, of things without parallel." - A.B.
    17. Re:I luv Perl, but... by tomhudson · · Score: 1
      The topic is debugging perl. Perl has a problem because it is not a very good language to begin with.

      Perl has its uses - but not on large projects or long lifetimes. Its ambiguities in terms of language structure renders it pretty much unmaintainable.

      As for the whole "learn to use the language" - I've been using it for years. In terms of maintainability of code, c has it beat by a mile. Perl has got to be one of the worst languages around in that respect. And that's what the topic is - debugging perl. I stick by my original contention that the quickest way to debug a perl program is to rewrite it in python. You'll not only get rid of your bugs, you'll have a program that's maintainable.

    18. Re:I luv Perl, but... by jonadab · · Score: 1

      > If you already have a decent background in c and at least one scripting language,
      > say php, you should be good to go.

      No PHP, and my C is _very_ marginal. However, I'm fluent in elisp and Inform, think in Perl, used to think in QBasic at one time, and have had some exposure to at least a dozen other programming languages. (By "some exposure" I mean enough to handily ace undergrad courses in the language, but not enough to do anything really serious or useful; my knowledge of Python is probably about this level, although I was doing it self-study, having previously graduated.)

      Like I said, maybe you just think Guido's Way. Some of us don't.

      --
      Cut that out, or I will ship you to Norilsk in a box.
    19. Re:I luv Perl, but... by tomhudson · · Score: 1

      used to think in QBasic at one time

      Ouch. My condolences :-)

      There were newspaper reports of a teenager who had to undergo therapy because he got to the point where he WAS thinking in basic. Literally. His thoughts, if he wanted to do anything, ended up being short snippets of "code", complete with line numbers.

  2. existent? by Bazzalisk · · Score: 0

    extant, surely?

    --
    James P. Barrett
    1. Re:existent? by daeley · · Score: 1, Interesting

      Pretty much synonymous:

      extant and existent.

      --
      I watched C-beams glitter in the dark near the Tannhauser gate.
    2. Re:existent? by The+Clockwork+Troll · · Score: 1

      Thanks for pointing out the existing synonyms.

      --

      There are no karma whores, only moderation johns
    3. Re:existent? by Anonymous Coward · · Score: 0

      Thanks for pointing out the existing synonyms.

      Oh that was real helpful. ;-D

  3. In defense of print statements by winkydink · · Score: 4, Insightful

    Properly placed and well-thought out, I can leave:

    print "a bunch o' stuff\n" if $Debugging;

    in my code forever and never have to go through the trouble of firing up an IDE.

    --

    "I'd rather be a lightning rod than a seismometer." -Ken Kesey

    1. Re:In defense of print statements by Billosaur · · Score: 2, Insightful
      print "a bunch o' stuff\n" if $Debugging;

      Alternatively, I convert print statements into logging facilities:

      open LOG, ">> $log_file" or die "Can't open $log_file: $!\n";
      # Magical happenings
      print LOG "And this happens here...\n" if $debug_flag;

      I can then match things up to my pseudocode and determine if I'm pushing values around the way I should. Of course it's made a a lot easier with "use strict;" and the -w switch enabled.

      --
      GetOuttaMySpace - The Anti-Social Network
    2. Re:In defense of print statements by hattmoward · · Score: 4, Insightful
      How many times is that conditional checked at runtime? They can add up. In perl, you could have it optimized away at compile time...
      sub DEBUG() { return 1; }

      ...

      DEBUG and print "value of blah:", $blah, $/;
      but... TIMTOWTDI ;)
    3. Re:In defense of print statements by winkydink · · Score: 1

      True that. If designing for performance, perl usually isn't the language choice I make.

      --

      "I'd rather be a lightning rod than a seismometer." -Ken Kesey

    4. Re:In defense of print statements by Mark_Uplanguage · · Score: 3, Informative

      When debugging I emphasize the use of "warn" over "print". It's the same syntax, but the warn statements don't get spooled and therefore their timing is quicker.

      This is vital when you code just plain blows up. Using "print" means that a statement which got executed before the disaster may not make it to console, thus leading you to believe that it never got executed. "warn" avoids this problem and thus leads you to the problem more accurately. It also makes it easy to globally comment out the warn statements before going releasing the code.

      --
      "The difference between stupidity and genius is that genius has its limits." -- Albert Einstein
    5. Re:In defense of print statements by codyk · · Score: 1
      Or you could just . . .

      use Smart::Comments;
      ### Expected: "a bunch o stuff" Got: $stuff

      . . . and have debugging statements that are easier to write, can be turned off in one place, and don't waste efficiency checking a bunch of conditionals.
      see http://search.cpan.org/~dconway/Smart-Comments-1.0 .1/lib/Smart/Comments.pm

    6. Re:In defense of print statements by irc.goatse.cx+troll · · Score: 1

      While I agree, I'd like to see a GUI ide that lets you fold debug prints down to a single red pixel line or something similar. Just so you can easily keep them around but yet be able to quickly scan through a page of code without being overwhelmed by a lot of prints.
      I still think vim is the best development environment, but even gtkvim is just a fancy xterm with a toolbar and menus. Hopefully soon a better developer than I will take vims powerful commands/features and mangle it into a full blown IDE with ctags, graphical debugger, proper folding, intellitext, etc (most of which its capable of doing now, just with an interface too poor to be useful day to day)

      --
      Pain lasts, kid. Its how you know you're alive. Sometimes I think this growing up thing is just pain management-TheMaxx
    7. Re:In defense of print statements by Baron+von+Leezard · · Score: 2, Interesting

      The issue of whether to use a debugger or not is a matter of speed and ease of debugging. There's few things you can't do with print statements that you can do with the debugger. [There are some: try using printf to get a backtrace of a segfault in C.] Lacing your program with print statements to check values is a time consuming, annoying, and certainly uglifies your code. Worse still, if you didn't anticipate wanting to see the value of some variable in advance, you will have to modify your program, (compile it), restart it, and get back to the point at which the bug is occuring--in some cases this can be very time consuming. With a debugger you don't have to anticipate anything. And you can modify values, which is often quite useful. [In Perl, as opposed to C, you can basically do anything you want in the debugger, including replace subroutines with new versions.] In some debuggers you can even try some stuff and then restart the current subroutine and step through it again from the beginning by popping the stack! [I'm not sure if you can do this in Perl, but gdb lets you do this for C programs].

      Admittedly, there is a time and place for everything. I especially favor print statements when you need to consider non-localized program behavior: compare values at many different points of the program or across many iterations of some loop. In such cases, using the debugger is usually annoying and far too slow. A really useful technique for this kind of debugging is to format the printf output so that it can be piped into a database like postgres or mysql. Once you have the debugging output in a database table, you have a really powerful way to pore through the data trying to figure out what's going on.

      [B/v/L]

    8. Re:In defense of print statements by hondo77 · · Score: 1

      That's cool and I don't doubt you but how do you know that gets "optimized away at compile time"?

      --
      I live ze unknown. I love ze unknown. I am ze unknown.
    9. Re:In defense of print statements by hunterx11 · · Score: 1

      The Camel Book does talk a bit about optimization: it is documented behavior that DEBUG in this case will be inlined, and that the right-hand side of "0 and" will not be evaluated.

      --
      English is easier said than done.
    10. Re:In defense of print statements by 5E-0W2 · · Score: 1

      Or you can use constant DEBUG=0; which is perhaps more straight-forward.

    11. Re:In defense of print statements by hachete · · Score: 1

      Log4Perl You know it makes sense.

      The only real way (the perl debugger sucks beyond belief and is only there for little bittie programs, and I've tried using it to debug client/server problems) is to use the perl debugger is through emacs, and the GUD interface, but I've given that up in favour of Log4perl.

      --
      Patriotism is a virtue of the vicious
    12. Re:In defense of print statements by CableModemSniper · · Score: 1
      I think you mean
      use constant DEBUG => 0;
      Note the "big arrow" operator, as opposed to the =. Of course the constant pragma does pretty much the exact same thing as sub DEBUG { return 0; } anyway.
      --
      Why not fork?
    13. Re:In defense of print statements by DrVomact · · Score: 3, Informative
      I programmed Perl for years and used nothing but print statements to diagnose my code. Then my boss took mercy on me and bought me a copy of the Active State Perl Developer Kit. This thing comes with a debugger that is actually easy to use--and it works! Wow. The program executes inside a window that allows me to step through the code, shows me variables I selected to be "watched", lets me set breakpoints by clicking on a line number...I haven't written a print statement since. Wait...maybe that's why I'm not getting any output...

      Disclaimer: I don't work for Active State, I don't own any piece of them and I'm not getting paid for writing this.

      --
      Great men are almost always bad men--Lord Acton's Corollary
    14. Re:In defense of print statements by 5E-0W2 · · Score: 1

      Ehm, yes, that one. Yeah, you can do it with typeglobs or subs or whatever you want.

    15. Re:In defense of print statements by jrockway · · Score: 1

      Ahh, your time is less expensive than that of a computer's. Interesting.

      BTW, you might want to take a look at mod_perl. It's speedy.

      --
      My other car is first.
    16. Re:In defense of print statements by winkydink · · Score: 1

      Again, if mod_perl fits the requirements, fine. If not, then another language.

      My comment was not about my time vs computer time, but overall program execution time.

      --

      "I'd rather be a lightning rod than a seismometer." -Ken Kesey

    17. Re:In defense of print statements by davie · · Score: 1
      Actually, you mean:
      sub DEBUG () { 0 };

      The empty prototype is a requirement.

      --
      slashdot broke my sig
    18. Re:In defense of print statements by Lord+Ender · · Score: 1

      That seems like a great idea, but it's not so good for CGI.

      --
      A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
    19. Re:In defense of print statements by johnMG · · Score: 1

      Using "print" means that a statement which got executed before the disaster may not make it to console,

      You could print STDERR though, since that's not buffered like STDOUT...

    20. Re:In defense of print statements by davorg · · Score: 2, Informative
      You could print STDERR though, since that's not buffered like STDOUT...

      Exactly. And that's what warn does. It prints to STDERR.

    21. Re:In defense of print statements by hattmoward · · Score: 2, Informative

      I didn't see that anyone gave you the full explanation here. What happens is during the compile pass (perl first does a parse/compile pass, then executes), it encounters the definition of sub DEBUG(). The closed parenthesis indicate that this sub will never accept any arguments -- not like a C prototype, more of a compiler hint. It effectively becomes a constant within this package that never needs to be written as DEBUG() because there is no ambiguity as to whether there are parameters. During the compile pass, it also sees that the return value of DEBUG will never change, and pretty much does an s/DEBUG/1/g or s/DEBUG/0/g to your code.

      More explanation here: http://www.xav.com/perl/lib/Pod/perlsub.html#const ant%20functions

      Combine that with perl's handling of logical operators, and it allows you to "short-circuit" the print statements when DEBUG evaluates to 0.

    22. Re:In defense of print statements by hattmoward · · Score: 1

      There's a nice debugger in Open Perl IDE, which unfortunately seems unmaintained. http://open-perl-ide.sf.net/

    23. Re:In defense of print statements by richardfoley · · Score: 1

      If you are writing your program entirely by yourself (one-man-band), you of course have more choice over print statements scattered liberally around. On the other hand, if you're working in a team, or are maintaining someone else's code, who may have left the company for instance, this choice becomes somewhat more limited. Different people may have different ideas about where to place print statements and what they should contain. In this case, being able to run and control the code, and what feedback to offer, without (adversely?) affecting anyone else can be very handy. You may have production code to debug, and are unable to, (read should not), change or move/copy it elsewhere, because of dependencies or circumstance. In this case, the ability to run your code and to modify it WITHOUT CHANGING THE SOURCE can be very useful. The debugger is one tool among many, use whichever suits your purpose and ability as appropriate. R.

  4. Compactness of language????? wtf by iggymanz · · Score: 1, Insightful

    Perl is a very bloated scripted language, now ruby is compact, and python somewhat compact, but Perl is surely the RPG-II of the scripting language world. And yes, I've been using Perl for over 9 years, and written tcp daemons and web portals in Perl. I love/hate it.

    1. Re:Compactness of language????? wtf by outZider · · Score: 1

      I think they speak of the actual structure of some people's Perl code, and not the size and breadth of the language and/or runtime.

      --
      - oZ
      // i am here.
    2. Re:Compactness of language????? wtf by caffeinemessiah · · Score: 1

      web portals ok, but what do you mean by a tcp daemon? Do you mean a TCP stack, in which case why would you use a scripting language (even though its highly optimizable) instead of C/C++? Or do you mean a TCP server? Even if it was the latter, if performance and code size is important to you, why didn't you use C/C++? Perl is great for prototyping performance-intensive apps, but if you deploy it for any serious performance-intensive tasks, you're making somewhat of a mistake. Also, I don't know how you can claim that Perl is a "very bloated" language. Do you mean that there are a bunch of modules out there, or that the core distribution is bloated? For the richness of functionality that Perl provides, I think it's doing a brilliant job in terms of size/features compared to, say, oh I don't know...Visual Studio??

      --
      An old-timer with old-timey ideas.
    3. Re:Compactness of language????? wtf by Anonymous Coward · · Score: 0

      stfu and get a clue you twit

    4. Re:Compactness of language????? wtf by Phroggy · · Score: 1

      Presumably he means a daemon that listens for incoming connections on a TCP port, and responds according to some protocol. And perl isn't nearly as slow as many people seem to think - it takes awhile to compile a large program, which happens at every runtime, but that shouldn't be a problem for a daemon.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    5. Re:Compactness of language????? wtf by ToasterofDOOM · · Score: 1

      Wrong and wrong. Perl is very compact, not only the language, but the interpreter as well. The actual interpreter is only ~1MB IIRC, and it's one of the only languages where programmers play 'Golf' and try to write a functional program in as few steps as possible. Fast, feature rich, and powerful, it's definitely not bloated.

      --
      I am Spartacus
    6. Re:Compactness of language????? wtf by iggymanz · · Score: 1

      bloated means amount of typing required to do a given task, not a terse nor powerful language compared to some. C/C++ in the same boat there, for power and terseness try OCAML or ruby. Tcp daemons means various database, queuing and xml services implemented as tcp servers and clients. Limiting factor of performance wasn't perl, was backend databases and repositories and such.

    7. Re:Compactness of language????? wtf by Anonymous Coward · · Score: 0

      better to remain silent and be thought a fool than speak and remove all doubt.

    8. Re:Compactness of language????? wtf by poopdeville · · Score: 1
      I thought the thread starter was referring to all of the syntactic sugar that makes games like Golf possible. The very basics of Perl -- what you'd learn in the first few chapters of "Learning Perl" are syntactically no harder than C. But if you jump into the wrong reference (or trying reading CPAN stuff as a beginner), you'll be quickly overwhelmed by the multitude of shortcuts.

      In my time as a Perl programmer, I've learned to use a lot of shortcuts where they make sense: with the fiddly bits that format my data. I use "verbose" C-like code for the business logic. While I've learned a lot, there's still a whole bunch I haven't encountered yet. Only the perl interpreter can parse Perl and all that.

      --
      After all, I am strangely colored.
  5. Obsolete before printing? by Jerry+Coffin · · Score: 3, Interesting
    Hmm...let's see: the basic idea here is that the book is devoted to the (text mode) debugger built into Perl, but even the review comes barely short of flat-out stating that nearly nobody is ever likely to be happy with this, and anybody doing any real work will want to use an IDE with a GUI-style debugger instead.

    I suppose this might be handy a bit the same way knowing something like ed or vi is handy for anybody using UNIX (or similar) systems -- even the absolute strangest distribution (or installation) will almost inevitably include at least that much and it's pretty consistent. OTOH, debugging Perl on a machine that hasn't really been equipped for it doesn't sound to me like a lot better idea than using ed to write most of my code...

    --
    The universe is a figment of its own imagination.
    1. Re:Obsolete before printing? by w.p.richardson · · Score: 1
      better idea than using ed to write most of my code...

      but, but, ed is the standard editor, dammit!

      --

      Curb CO2 emissions: Kill yourself today!

    2. Re:Obsolete before printing? by Baron+von+Leezard · · Score: 2, Insightful

      I've been a serious Perl programmer for about eight years, and I never use an IDE. I always do my debugging at the terminal. [I do use a syntax highlighting editor.] I understand that a lot of people like IDEs, but I find them annoying and hampering. I'd prefer to have a text mode debugger pipe a large data structure to less and let me use / and ? to find various things in the pager. I haven't found an IDE yet that lets you do that easily. This is a very useful technique--especially in the perl debugger, where you can run arbitrary perl code at any point in the program and pipe the output to a pager.

      Moveover, you're assuming that you can run an IDE in your development environment. I often have to work on deployed server systems that have neither a windowing system not an IDE installed. However, I can always run the perl debugger and interact with it in an SSH session.

      [B/v/L]

  6. Credentials completely shot in 3rd PP by beacher · · Score: 1
    Okay this make me choke on my MD - "He's presently working for Amadeus, on an automated software testing application for their flight booking system."

    Also, lets see if we can debug the website and make that next button work......Not functioning in FF1.5/Win
    -B

    1. Re:Credentials completely shot in 3rd PP by richardfoley · · Score: 1

      It might be worth remembering that in anything other than a perfect world, testing is likely to reduce, but will never eliminate all bugs. Why? Because humans write computer programs. Knowing how to use any form of debugging tool, (print statement or otherwise), can be an advantage in finding and eliminating the problem. Of course when you're trying to debug a moving target like javascript, (on both FF and IE at the very least), now there's a whole new can of worms ;-) R.

    2. Re:Credentials completely shot in 3rd PP by richardfoley · · Score: 1

      Did I mention I don't fly ?-) R.

  7. Perl makes bugs very hard to spot by Anonymous Coward · · Score: 5, Funny

    The only thing harder to spot in Perl is the good code. My rule of thumb is: If I can understand it easy in Perl, it's probably a bug.

  8. Debugging?! by ObsessiveMathsFreak · · Score: 4, Funny

    Debugging perl? Doesn't that defeat the whole point?

    --
    May the Maths Be with you!
    1. Re:Debugging?! by aled · · Score: 1

      You mean that Perl is some kind of programming language? and that it can be debuged? Nonsense!

      --

      "I think this line is mostly filler"
  9. If it's Tuesday . . . by rodentia · · Score: 4, Funny

    this symbol must be scalar.

    Unless the moon is gibbous.

    --
    illegitimii non ingravare
    1. Re:If it's Tuesday . . . by svanstrom · · Score: 1

      Nah, it's easy to understand what's what, just have a look at my sig... =)

      PS I'm sorry if that perl oneliner doesn't work when you try it, but I'm taking the server offline for short periods of time while doing some upgrading... If it's down when you try it just try again a minute later.

      --
      perl -e'print$_{$_} for sort%_=`lynx -dump svanstrom.com/t`'
  10. I once tried to debug a perl script... by Anonymous Coward · · Score: 0

    I once tried to debug a perl script, but the problem was obvious. The 'programmer' who originally wrote the script had just made a symlink to /dev/urandom.

  11. use strict and Data::Dumper! by licamell · · Score: 4, Insightful

    #! /usr/local/bin/perl
    #
    # Two things that make debugging perl easy:
    #

    use strict;
    use Data::Dumper;



    The first one will solve most peoples perl problems, and the second one is helpfull sometimes when dealing with complex datastructures.

    1. Re:use strict and Data::Dumper! by John+Bokma · · Score: 1

      The only time I used the debugger was to figure out why an update of a CPAN module suddenly misbehaved. I don't understand that people need a debugger at a weekly, or even daily basis. And I really don't understand the need for a book about it.

      I one was hired by a company that did a lot of C programming, and if there was something not working right, the rule was you had to fire up the debugger, and single step. I ignored that silly advice, and added a print statement, or reread my code.

    2. Re:use strict and Data::Dumper! by Baron+von+Leezard · · Score: 1

      [That's one freelance Perl programmer I'll have to remember never to hire.]

      Seriously, I'm one of those people who use a debugger every day. Actually, when I write new code in Perl, often the first thing I do is step through it in the debugger to make sure it does what I think it should. Especially in Perl, it is very easy to accidentally do something that's a little off. With the "wait until something goes wrong before I investigate" attitude demonstrated here, you'll never know anything is amiss until some nasty bug crops up as a result. Using the debugger to sanity check my code means that I catch most bugs before they ever cause problems.

      I'm sure I'm going to get some snide remarks about this approach, but really, I've been a serious Perl programmer for about eight years now, and often write moderately complex Perl programs that work perfectly the first time--run through the debugger or not. I can't say that about any other language, and it's something most people can't say about any language, let alone Perl ;)

      [B/v/L]

    3. Re:use strict and Data::Dumper! by Mitglieder · · Score: 1

      strict prevents you from doing some things with hashes which are valid code, so it came as a shock to once discover that strict itself was the bug. I hate how much of the stuff strict warns over doesn't stop the program from actualy working. It's like if the program would have ran fine anyway just run and be done with it so I can get on with my life. It's perl, it's not like it's ever going to be a piece of fine jewelry.

    4. Re:use strict and Data::Dumper! by Anonymous Coward · · Score: 0

      # one more helpful line

      use warnings;

    5. Re:use strict and Data::Dumper! by talexb · · Score: 1
      Actually, when I write new code in Perl, often the first thing I do is step through it in the debugger to make sure it does what I think it should.

      Excellent. A coder with the same ideals. I do this for Perl, and I did the same thing in C -- run it in the debugger, but only after a severe thrashing through PC-lint (Gimpel Software?) until it came out squeaky clean.

      Why? To make absolutely sure that the machine and I are in perfect agreement about what the expected behaviour is. It's time consuming, but better to spend a few hours doing that before the code is released than a few days afterwards, trying to chase down that elusive bug, while the VPs pace around, glancing darkly in your direction, and Marketing calls you frantically every hour.

    6. Re:use strict and Data::Dumper! by deranged+unix+nut · · Score: 1

      Print statements don't work very well in a lot of places.

      For example, when the run takes 5 hours and the problem is in the last 5 minutes. Or when your C/C++ code sits in a kernel mode driver.

      Debuggers exist for a reason.

    7. Re:use strict and Data::Dumper! by bahwi · · Score: 2, Interesting

      But what about this?

      use Coy;

    8. Re:use strict and Data::Dumper! by John+Bokma · · Score: 1

      Instead of using a debugger, I prefer to use intensive regression testing. Tests I wrote down in the design phase, and often refine during actual implementation.

      I hope you understand the difference: with regression testing I can check many, many design specification in an extremely short time. Moreover, I can give my regression tests to other developers. Can you do the same with your debugger gazing sessions?

      I rarely have to "think" what a piece of Perl code does, because I either know, or I read the fine manual.

      And I certainly don't have to fire up a debugger (daily for crying out loud) to check if my code does what I think (again for crying out loud) does.

      I've been a serious Perl programmer for about eight years now

      Certainly you're joking my dear Baron?

      Even if you could hire me, I doubt I could work with you (ouch)

    9. Re:use strict and Data::Dumper! by John+Bokma · · Score: 1

      Maybe you t(w)o(o) should (both) read up on regression testing.

    10. Re:use strict and Data::Dumper! by Baron+von+Leezard · · Score: 1

      I'm all for regression testing. Refusing to regression test, and insisting on using only debugging would be silly. The converse, however — refusing to use a debugger, and insisting on using only regression testing — is just as silly. Debuggers are extremely useful tools that are very appropriate in many programming situations. Any professional programmer who flat out refuses to use a debugger — and moreover derides those who do — is someone whose general views on programming I would find suspect.

      [B/v/L]

    11. Re:use strict and Data::Dumper! by John+Bokma · · Score: 1

      I never stated that I refused to use a debugger. I even told you that I used the perl debugger this year. But in my own code? I can't think of a situation that I needed a debugger. And certainly not everyday.

      I have been working in an environment though, were other programmers did fire up a debugger everytime something went wrong. A second look at the code, or a simple printf (it was C), would probably have saved some time, and for those that had troubles with setting breakpoints, and did single step through every loop it would have been a major time saver.

      Like I said, I manage perfectly without a debugger most of the time. But when I think it's the right tool to use, I wouldn't think twice, but just use it (like I said: I did use it once this year ;-)).

      Your comment, though, and your replies, made it sound that you consider everyone who doesn't use a debugger daily a bad programmer. That's as silly as stating that you never are going to use a debugger, no matter what. The quality of a programmer is measured by what he/she delivers, not on what tools he/she uses, especially if one insists that such a tool has to be used daily, just because, which reminds me of one guy working in that C environment, who just pressed the arrow keys rappidly when he was explaining something to me. When I asked why he was doing that, he explained that it made us look working hard... Maybe you and he could be excellent coworkers :-) (and I chip two of those managers in for free)

    12. Re:use strict and Data::Dumper! by Anonymous Coward · · Score: 0

      The entire point of a process is that when following the process, the end result is intended to be, on average, better than if the process were not used. That is to say that the quality of the deliverable is influenced by the tools of the developer. This isn't necessarily the case, but it's certainly the case more of the time than the arrogant proclamations of some nobody freelance Perl developer from Mexico.

      Rerunning unit testing is rather insufficient for ensuring correctness. It is essentially one small piece for testing invariants, and doesn't substitute anywhere for the use of a debugger where such a tool is useful. It doesn't show a picture of the running program at all, and nontrivial software is rarely capable of just being looked at to determine fault unless formal methods are being utilized. So I can assume that you largely work on small projects if you find yourself dealing with a debugger a grand total of once within an entire year. And I can assume the Baron has a lot of free time if he can single step through every revision he makes to a codebase in a debugger.

      You let the rest of us know when you two actually develop software.

    13. Re:use strict and Data::Dumper! by lachlan76 · · Score: 1

      If you need to you can use "no strict refs;" or something along those lines. Look up strict in perldoc and you'll find some more information about it.

  12. Debug this... by Cherita+Chen · · Score: 3, Funny

    #!/usr/bin/perl $_='A=15; B=30; select(stdin); $|=1; select(stdout);$|=1; system "stty -echo -icanon eol \001"; for C(split(/\s/,"010.010.010.010 77.77 022.020.020 330.030.030 440.044.000 055.550.000 666.060.". "000")){D=0;for E(split(/\./,C)){F=0;for G(split("",E)){C[P][F++ ][D]=G} D++}J[P]=F; I[P++] =D}%L=split(/ /,"m _".chr(72)." c 2". chr(74)." a _m");sub a{for K(split(/ /,shift)){(K,L)=split(/=/,K );K=L{K};K=~s/_/L/; printf "%c[K",27}}sub u{a("a=40");for D(0..B -1){for F(0..A-1){M=G[F][D];if(R[F][D]!=M) {R[F][D]=M;a("m"."=". (5+D).";".(F*2+5)); a("a=".(40+M).";" .(30+M));print " "x2}}}a( "m=0;0 a=37;40")}sub r{(N)=@_;while(N--) {Q=W;W=O=H;H=Q;for F( 0 ..Q-1){for D(0..O-1) {Q[F][D]=K[F][D]}}for F(0..O-1){for D(0..Q- 1){K[F][D]= Q[Q-D-1][F]}}}}sub l{for F(0..W-1){for D(0..H-1){(K[ F][D]&& ((G[X+F][Y+D])|| (X+F=A)|| (Y+D>=B)))&& return 0}}1}sub p{for F(0..W-1){for D(0..H-1){(K[F][D]>0)&&(G[X+F][Y+D] =K[F][D]) }}1}sub o{for F(0..W-1){for D(0..H-1){(K[F][D]>0)&&(G[ X+F][ Y+D]=0)}}}sub n{C=int(rand(P)) ;W=J[C];H=I[C];X=int(A/2)-1 ;Y=0;for F(0..W-1){for D(0..H-1){K[F][D]= C[C][F][D]}}r(int(rand (4)));l&&p}sub c{d:for(D=B;D>=0;D--){for F(0..A-1){G[F][D]||next d}for(D2=D;D2>=0; D2--){for F(0..A-1){G[F][D2]= (D2>1)?G[F][D2-1 ]:0; }}u;}}a ("m=0;0 a=0;37;40 c");print "\n\n".4x" "." "x(A-4). "perltris\n".(" "x4)."--"xA."\n".((" "x3)."|"." "x(A*2)."|\n")xB .(" "x4). "--"xA."\n";n;for(;;) {u;R=chr(1); (S,T)=select(R,U,V, 0.01);if(S) {Z=getc;}else {if($e++>20){Z=" ";$e=0;}else{next;} } if(Z eq "k"){o;r(1);l||r(3);p}; if(Z eq "j"){o;X--;l||X++;p}; if (Z eq "l"){o;X++;l||X--;p};if(Z eq " "){o;Y++;(E=l)||Y--;p;E|| c |c|c|c|c|n||goto g;};if(Z eq "q"){last;}}g: a("a=0 m=".(B+8).";0 " ); system "stty sane"; '; s/([A-Z])/\$$1/g; s/\%\$/\%/g; eval;

    --
    I'm not fat, just big boned...
    1. Re:Debug this... by garcia · · Score: 0, Flamebait

      Debugged the fact that you're lame as hell. Don't do that, it's really pointless.

    2. Re:Debug this... by anandamide · · Score: 1

      It seemed to work OK for me. Exactly what problems are you seeing?

    3. Re:Debug this... by Phroggy · · Score: 5, Informative

      You accidentally used = instead of == in a conditional.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    4. Re:Debug this... by Billly+Gates · · Score: 0, Redundant

      I dont know which is scarier?

      The code or the fact that you read it and understood it at plain site???

      God I have some perl scripts but I am afraid to put advertise that I wrote them on my resume. That code proves to me what I never want to become a professional perl programmer if my life depended on it.

      Shudder

    5. Re:Debug this... by Phroggy · · Score: 3, Informative

      I dont know which is scarier?

      The code or the fact that you read it and understood it at plain site???


      The code is obfuscated. It basically takes a really big string, and runs it through a couple of regex substitutions to turn it back into perl code, then eval's it. I replaced "eval" with "print", which made it output the code instead of executing it, then I used "perl -MO=Deparse" to clean it up. This gave a compilation error at ($X+$F=$A). Changing that to ($X+$F==$A) makes it compile... but Deparse optimized several whole subs away entirely, and I really don't care enough to figure out exactly what it's supposed to do.

      And no, I'm not going to run it.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    6. Re:Debug this... by Anonymous Coward · · Score: 0

      It's a tetris game.
      Fix the error: 'X+F=A' should be 'X+F==A'.
      Save and run.
      Play with j, k, l, space and q.

      Robin.

  13. My favorite by jason8 · · Score: 1
    I like to fire up the debugger via
    perl -d -e ';'
    which starts an interactive Perl debugger session. It's very useful for quickly seeing how snippets of code will behave.
    1. Re:My favorite by Baron+von+Leezard · · Score: 1

      Even shorter is "perl -de0". Actually, I do this so much that I have it aliased to "perld".

      [B/v/L]

    2. Re:My favorite by hunterx11 · · Score: 1

      Obviously perl -de42 is superior.

      --
      English is easier said than done.
  14. Re:Who Uses Perl Anymore? by gregarican · · Score: 1, Troll

    I figure this parent post will be flagged as Flamebait, but I agree. Perl != Relevant anymore.

  15. Re:Who Uses Perl Anymore? by outZider · · Score: 2, Informative

    Nah, you're just going to be marked as someone who doesn't know what's going on. Perl is very relevant, used in a lot of high profile areas. I don't know what you think 'replaced' perl, but I know that a lot of languages have 'joined' it in many tasks. Web development, system administration, you name it.

    --
    - oZ
    // i am here.
  16. bring on the trolls by Anonymous Coward · · Score: 0

    we don't care if you think perl produces gibberish intelligent people effectively use perl every day, we seem to cope just like the lisp folks, C junkies, etc i no longer care if you can read it, i will continue to write one line of perl where you write twenty lines of java.

  17. Reviewer is obviously not a programmer by gcauthon · · Score: 0, Troll
    The typical computer program has more bugs than there are ants at a picnic -- except ants are usually easier to find

    In other words, the reviewer is a horrible programmer. Maybe he should stick to reviewing books about writing web sites, or whatever his consulting service does. His review is full of buzz words that he probably picked up through Google. Nowhere does he show any insight into testing/debugging a modern program. The book may or may not be any good, but we'll never know based on this review.

    1. Re:Reviewer is obviously not a programmer by richardfoley · · Score: 1

      I wouldn't like to comment too harshly on the review, because as far as the book goes, as someone once said: "all advertising is good advertising". ;-) R.

  18. Print statements by Anonymous Coward · · Score: 3, Interesting
    As a result, some disheartened Perl coders eventually switch back to embedding "print" statements in their code. Fortunately, there is a better alternative

    Actually, after ~25 years of writing code, I've found that 'print' statements are the best alternative. I've used every kind of debugger and IDE in the past, but in the last couple of years I've found that I rarely use them.

    When you're in a debugger, you're down in the trees and it's hard to see the forest. With skillfully placed print statements that pick out the relevant data, stack traces for exceptions and a decent language, you can get a commanding overview of what's going on in your app. With a good editor, you can manipulate print statements just about as fast as breakpoints in an IDE, too. Just map a function key in your editor to "save file; make go".

    1. Re:Print statements by ThinkFr33ly · · Score: 1

      Except that you can still use print statements (or System.Diagnostics.Debug.WriteLine, or whatever) in conjunction with a good IDE.

      In fact, the best IDEs allow you to have the value of a variable or expression printed every time a particular part of your code is hit, without modifying that code at all. (VS.NET, for instance.)

      In the end, you really shouldn't have to modify source code to figure out the value of variables at various points in the execution of that code.

    2. Re:Print statements by rzebram · · Score: 1

      Just map a function key in your editor to "save file; make go".

      make: *** No rule to make target 'go'. Stop.

    3. Re:Print statements by Anonymous Coward · · Score: 0
      In the end, you really shouldn't have to modify source code to figure out the value of variables at various points in the execution of that code.

      Why not? Like I said, it's really no big deal with the right tools.

      Another problem with IDEs is that they're huge, usually not cross-platform, they support those cool tricks for only a small selection of languages, and they are especially bad at those tricks if you're using multiple languages in the same project (maybe with the exception of .NET stuff, but that's totally locked to one platform). Oh, and good luck figuring out how to build your project again if you put it to the side for a few years.

  19. older books by Anonymous Coward · · Score: 2, Informative

    Thanks, I'd like to remind everybody that the 3 older books are still very worthwhile:

    Effective Perl, Hall and Schwartz
    Debugging Perl, Martin Brown
    Perl Debugged, Scott / Wright

  20. debugging loops by abiessu · · Score: 2, Interesting

    I've found that debugging loops can be tedious in most of the 'normal' ways of going about it. I finally got sick of lots of 'print' output and discovered that using 'warn' statements and trapping the '__WARN__' signal (using a BEGIN) provided an especially effective method of debugging loops: store the warning text as the key of a hash where the value is incremented each time. Inside an END block, write the contents of the hash to your favorite stream.

    This method will debug loops of all kinds, and if each 'warn' is labeled well, it's very easy to see what happened.

    (Note: the above may or may not depend on the use of '#!/usr/bin/perl -w' (warnings) as your interpreter.)

    --
    Let S_n = {nst+us+vt : s,t in Z \ {0}, u,v in {-1,1}}. For all n in Z where |n| > 2, Z \ S_n is infinite... right?
  21. Watched variables by lewiscr · · Score: 3, Informative

    > More specifically, watching a variable change value, while stepping
    > through the lines of a Perl script using the debugger, requires that
    > the programmer manually or programmatically echo that variable's value,
    > by issuing a print command ("p") followed by the variable name, one
    > way or another.

    $ perl -d -e 1
        DB h ...
        h [db_cmd] Get help on command w expr Add a watch expression
        h h Complete help page W expr|* Delete a/all watch exprs ...

    Admittedly, the watch expressions don't detect changes in deep data structures. But it works just find on dependant expressions. I'll regularrly set watches on a loop index and a data structure being indexed by said loop var. The watch expressions will display both results.

    In addition, the 'x' command works much better than 'p'. 'x' dumps the data structure, so it will display arbitrarily complex and deep data.

  22. Re:Who Uses Perl Anymore? by wonko_el_sano · · Score: 2, Informative

    Tell me, what major sites have been build using Ruby?

    I can list several very high volume sites/applications that use Perl.

  23. Perl debugger is fine, Log::Log4perl way better by talexb · · Score: 4, Informative

    I love the debugger -- my background is BASIC, assembler, C and finally Perl, so it fits right in with all those "programmning down to the bare metal" tools.

    However, a way cooler method is to use logging. The one I use these days is Log::Log4perl, a terrific logger that you can turn on and off at will. Thus, if you have a bit of disk space, you can turn the knob up to 11 (DEBUG) and let the application go until you get to the Weird Bug. Then it's just a matter of pawing through the log files to find all of your excellent messages. Print statements sprinkled through the code? Please.

    And the bit about having to print the variable value every step in the debugger is a bit of a red herring .. you can set up commands that get executed before and after each step. Yes, it's a geeky thing to do .. that's why they call it Engineering.

    1. Re:Perl debugger is fine, Log::Log4perl way better by Anonymous Coward · · Score: 0
      However, a way cooler method is to use logging. The one I use these days is Log::Log4perl, a terrific logger that you can turn on and off at will. Thus, if you have a bit of disk space, you can turn the knob up to 11 (DEBUG) and let the application go until you get to the Weird Bug. Then it's just a matter of pawing through the log files to find all of your excellent messages.


      And then you have to write a program to step through all your log statements to reconstruct your programs run-time stack as it ran, and figure out what your computer was *doing* when it hit the Wierd Bug(TM).


      Or you can use the program that does all that already; it's called the perl debugger. The stack trace feature will tell you what functions you called to hit the Wierd Bug, and what arguments they were passed, and you can then usually see trivially what's wrong. If you can't, you can always walk down the call stack looking for flaws at each stage; you must have one, or you wouldn't have a bug.


      I use logging only when I have program that I can't run from the debugger; it's a much less convenient way of finding out what's going on, because I have to either wade through reams of stuff I don't want, OR re-run repeatedly increasing the logging switches to narrow things down to the set of logging switches that describe my problem. I'd just as soon do it all in one run, thanks.


      Just my $0.02
      --
      AC

  24. One question by teslatug · · Score: 1

    Whenever I use the perl debugger, I find that I have to hit enter (after pressing n, or s) over and over, is there a way to tell it to do something x number of times, like n 5?

    1. Re:One question by Baron+von+Leezard · · Score: 1

      It's not exactly what you want, but "c " will continue until hitting the line number given. Combined with "l" to list the code in the lines after the current line, this allows you get the effect you want. Another useful trick is setting conditional breakpoints: the syntax is "b ". As always, the condition can be arbitrary perl code.

      [B/v/L]

    2. Re:One question by Tired+and+Emotional · · Score: 1

      You can write a perl script to do that!

      Just redirect stdin and stdout to your script, fire up the program in debug mode and have your script feed it debug commands until something interesting (which of course you have predetermined) happens, or in response to your own input (you have of course saved the original stdin and stdout handles so you can still do io to your own program).

      Actually, I have only ever done this with gdb but I expect it will work with perl debug too.

      --
      Squirrel!
    3. Re:One question by teslatug · · Score: 1

      It doesn't work for loops though. The conditional breaking may help, but that means doing some thinking every time this situation comes up. Not the end of the world, but it's such a simple thing that I would hope the perl debugger could implement.

  25. I spent a week debugging Perl code by Anonymous Coward · · Score: 0

    By the time I was done, it had turned into C code.

  26. PRO perl debugging? by infinite9 · · Score: 2, Funny

    Personally, I'm anti perl debugging.

    --
    Disconnect your television. Do your own research. Draw your own conclusions. They're probably lying. Don't be a sheep.
  27. Mod down, same kaleidojewel spam as always. by Anonymous Coward · · Score: 1, Informative

    Yet another instance of spamming the book reviews with his Amazon-referral-laden links.

    And "if you're a pro, why do you need to debug"? Clearly he has no clue about programming, and is only in it for the $0.05 per click you give him.

  28. Re:Who Uses Perl Anymore? by Lost+Found · · Score: 1

    You seem to have forgotten Amazon.com, which uses HTML::Mason (a Perl/mod_perl templating system) to serve every customer-facing page.

  29. linking to C libraries by bcrowell · · Score: 2

    For me, the real problems come when I'm debugging a Perl program that's linked to someone else's C library. I have an app that had been stable for a long time, until I found that with recent releases of Perl/Tk it suddenly started crashing once a week or so. A stack trace shows that it's crashing inside a certain C function in Perl/Tk, but my lack of C skills have stopped me from getting to the point where I could file a useful bug report. This is what I really need a book on. AFAICT, I would have to compile Perl/Tk myself using certain options, and the options that work for most C software don't actually seem to be the right ones for Perl/Tk. Then I would have to dust off my decades-old C and C debugging skills and figure out what was wrong. Ugh!

    1. Re:linking to C libraries by richardfoley · · Score: 1

      Oh dear, 'crashing once a week or so' and 'inside a certain C function' sounds exciting. It might be worth looking at attaching gdb to the running process, that way, when it crashes, (at some indeterminate time in the future), gdb may have a handle on the particular point. Sometimes we have to use the most appropriate tool for the job / correct screwdriver... R.

  30. Re:Who Uses Perl Anymore? by VENONA · · Score: 1

    I do. So do about half the *IX people I know. It won't be obsolete any time soon.

    Not everything needs objects, though Perl can certainly do that. Also, there are fairly large bodies of code written in Perl, which require maintenance. What most orgs use for an IT budget these days isn't going to allow a rewrite of running code unless there's a very clear reason for it. I most cases, you'd have to prove a stunning performance win, or some thumping great decrease in maintenance costs, etc. It would probably not be easy to do.

    If you'd said less relevant, I'd probably have agreed with you, though with some exceptions, like system admin. But not relevant? Nah, I can't buy that at all.

    --
    What you do with a computer does not constitute the whole of computing.
  31. Better yet: by Anonymous Coward · · Score: 0

    I like to use a hash and a function, so there's a finer control over which sections of code are debugged. That way once a section is working as advertised, I can easily shut off debugging output for it. Likewise, using labels like "normal", "serious", "verbose", or "wtf" can let you escalate the debugging level and drop it back as needed.

    $Debugging = 1;
    $DBG{'regex'} = 1 * ${Debugging} * 1;
    $DBG{'html'} = 1 * ${Debugging} * 2;
    $DBG{'higher'} = 1 * ${Debugging} * 4;

    sub debug
    {
    local ($type, $text);
    $type = shift;
    $text = shift;
    if($DBG{$type}) {print "[DBG $type: $text ]\n";}
    }


    main:
    {
    my($i);

    while($_=<>)
    {
    $i++;
    debug('html',"got to $i, $_");
    debug('another_level',"this won't print");
    print;
    }
    }
  32. This guy is making money off this post by Billly+Gates · · Score: 3, Informative

    Barnes & Noble pays for references aka clicks just like amazon and the click links to his account.

    Also work4hire refers to his website to make his google page rank go up.

    1. Re:This guy is making money off this post by Anonymous Coward · · Score: 0

      What's wrong with either of those?

  33. Re:Who Uses Perl Anymore? by Anonymous Coward · · Score: 0

    Also, there are fairly large bodies of code written in Perl, which require maintenance.

    Yep, they require lots of maintenance, because perl is crap.

  34. What about more intuitive tools? by Rocko+Bonaparte · · Score: 1

    I've found myself lately using the open perl IDE (http://open-perl-ide.sourceforge.net/) for debugging. I can set breakpoints in it and trace variables in a little bar on the side. It isn't perfect--I don't know how well it works in a multithreaded environment in particular, but it has saved my ass many times. Of course it can't fix the "Not a SCALAR reference" crap when dealing with various data types, but that's where Perl 6 will fix things.

    --
    No I'm not trolling.
  35. You must not maintain servers by Mitglieder · · Score: 1

    Perl is still a great replacement for shell scripts, sed and awk. It's native regex support is ahead of it's time. You can do crazy string manipulation and statistical gathering with no effort at all. A bunch of web log parsers were written in Perl and it's easy to see why, because the language was designed for that sort of purpose. Perl is to server administration and string parsing what PHP is to CGI.

    1. Re:You must not maintain servers by gregarican · · Score: 2, Informative

      If you delve into Ruby for such tasks and then take a look back at Perl perhaps you'll understand where I am coming from. For admin scripting, text parsing, etc. it's just as powerful. But easier to read, more logical, and more concise. I know I misspoke when I said Perl is irrelevant. It still has a big place in a lot of projects out there. But with languages like Ruby out there hopefully its days are numbered...

  36. Re:Isn't it time to bury Perl? by speculatrix · · Score: 1
    the language is bloated, cryptic

    yeah, but for real job security, nothing's as good as being the only person to understand the company's major application written in perl, and even better, you don't have to try very hard to make it so!!!

    -- Note to mods: this is an attempt at humour.
  37. Re:Who Uses Perl Anymore? by VENONA · · Score: 1

    Yawn.

    --
    What you do with a computer does not constitute the whole of computing.
  38. IDEs? by rpg25 · · Score: 1

    Given that a big theme of the article is that graphical IDEs are better than the debugger for almost all purposes, it would be nice to have a list of some of these perl-capable IDEs so that we can assess the claim.

  39. Interview with Richard Foley by ArkieNerd · · Score: 1

    If you want to hear an interview with Richard about the book, you can download the audio from http://perlcast.com/2005/11/23/interview-with-rich ard-foley/.

  40. Especially once they finish porting CPAN... by Anonymous Coward · · Score: 0

    It's only 17 million lines of documented unit tested code (ignoring the 1 million lines of crap), it should only take what... 4-5 years?

  41. Re:Who Uses Perl Anymore? by feijai · · Score: 1

    And don't forget all those high-volume sites using Visual Studio.

    Luke's First Law of the Computer Industry: Quality is inversely proportional to Popularity.

  42. first half of the deparsed code by Phroggy · · Score: 2

    #!/usr/bin/perl

    $A = 15;
    $B = 30;
    select stdin;
    $| = 1;
    select stdout;
    $| = 1;
    system "stty -echo -icanon eol \cA";
    foreach $C (split(/\s/, '010.010.010.010 77.77 022.020.020 330.030.030 440.044.000 055.550.000 666.060.000', 0)) {
        $D = 0;
        foreach $E (split(/\./, $C, 0)) {
            $F = 0;
            foreach $G (split(//, $E, 0)) {
                $C[$P][$F++][$D] = $G;
            }
            ++$D;
        }
        $J[$P] = $F;
        $I[$P++] = $D;
    }
    (%L) = split(/ /, 'm _H c 2J a _m', 0);
    sub a {
        foreach $K (split(/ /, shift @_, 0)) {
            ($K, $L) = split(/=/, $K, 3);
            $K = $L{$K};
            $K =~ s/_/$L/;
            printf "%c[$K", 27;
        }
    }
    sub u {
        a 'a=40';
        foreach $D (0 .. $B - 1) {
            foreach $F (0 .. $A - 1) {
                $M = $G[$F][$D];
                if ($R[$F][$D] != $M) {
                    $R[$F][$D] = $M;
                    a 'm=' . (5 + $D) . ';' . ($F * 2 + 5);
                    a 'a=' . (40 + $M) . ';' . (30 + $M);
                    print ' ' x 2;
                }
            }
        }
        a 'm=0;0 a=37;40';
    }
    sub r {
        ($N) = @_;
        while ($N--) {
            $Q = $W;
            $W = $O = $H;
            $H = $Q;
            foreach $F (0 .. $Q - 1) {
                foreach $D (0 .. $O - 1) {
                    $Q[$F][$D] = $K[$F][$D];
                }
            }
            foreach $F (0 .. $O - 1) {
                foreach $D (0 .. $Q - 1) {
                    $K[$F][$D] = $Q[$Q - $D - 1][$F];
                }
            }
        }
    }

    --
    $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
    $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
  43. part 2 (working around lameness filter) by Phroggy · · Score: 1

    sub l ;
    sub p ;
    sub o ;
    sub n ;
    sub c ;
    a 'm=0;0 a=0;37;40 c';
    print "\n\n" . 4 x ' ' . ' ' x ($A - 4) . "perltris\n" . ' ' x 4 . '--' x $A . "\n" . (' ' x 3 . '|' . ' ' x ($A * 2) . "|\n") x $B . ' ' x 4 . '--' x $A . "\n";
    n ;

    --
    $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
    $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
  44. part 3 (working around lameness filter) by Phroggy · · Score: 1

    while (1) {
        u ;
        $R = chr 1;
        ($S, $T) = select($R, $U, $V, 0.01);
        if ($S) {
            $Z = getc;
        }
        else {
            if ($e++ > 20) {
                $Z = ' ';
                $e = 0;
            }
            else {
                next;
            }
        }
        if ($Z eq 'k') {
            o ;
            r 1;
            r 3 unless l ;
            p ;
        }
        if ($Z eq 'j') {
            o ;
            $X--;
            $X++ unless l ;
            p ;
        }
        if ($Z eq 'l') {
            o ;
            $X++;
            $X-- unless l ;
            p ;
        }
        if ($Z eq ' ') {
            o ;
            $Y++;
            $Y-- unless $E = l();
            p ;
            goto g unless $E or c() | c() | c() | c() | c() | n();
        }
        if ($Z eq 'q') {
            last;
        }
    }
    g: a 'a=0 m=' . ($B + 8) . ';0 ';
    system 'stty sane';

    --
    $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
    $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    1. Re:part 3 (working around lameness filter) by tootlemonde · · Score: 1

      Phroggy, I gotta say it. You the man.

    2. Re:part 3 (working around lameness filter) by richardfoley · · Score: 1

      Phroggy, Yours is an excellent example of using the right tool for the job! 10/10 :-) R.

  45. Horrible Code I must debug by Loundry · · Score: 1
    The worst thing about Perl is its coders. I willfully self-impugn with that statement. That said, here's a taste of what I have to debug.
    for($tmp=0;@tmp>$tmp;++$tmp) {
    tool_call($tmp[$tmp][0],$tmp[$tmp][1],$tmp[$tmp ][2],$tmp[$tmp][3],$tmp[$tmp][4],$tmp[$tmp][5],$tm p[$tmp][6],$tmp[$tmp][7],$tmp[$tmp][8],$tmp[$tmp][ 9],$tmp[$tmp][10]);
            }
    I just love "@tmp>$tmp", meaningful variable names and all.

    Here's another one:
    sub Tmploop {
    my (@args,@data,$tmp,$tmp2);
    @args=@_;
     
    for($tmp=0 ;@{$args[1]}>$tmp;++$tmp) {
    my %hash;
            # for every variable if defined
            for($tmp2=0;@{$args[0]}>$tmp2;++$tmp2) {
                    if(defined($args[1]->[$tmp][$tmp2])) {
                            $hash{$args[0]->[$tmp2]}=$args[1]->[$tmp][$tmp2];
                      }
            }
    push(@data,\%hash);
    }
    return \@data;
    }
    @args, @data, %hash, $tmp, and, as an extra bonus, $tmp2! All in an ultra-meaningfully-named function called "Tmploop". I'm glad that the comment "for every variable if defined" was included, as the ultra-obscure meaning of the for loop was severerly clouding my understadning of what $tmp2=0;@{$args[0]}>$tmp2;++$tmp2 was trying to convey.

    I've described debugging this former associate's code as "the herpes of this job".
    --
    I don't make the rules. I just make fun of them.
    1. Re:Horrible Code I must debug by whenyouargue · · Score: 1

      I really don't think that the original coder understood Perl, and attempted to use principals from other languages, and very badly at that.

      for($tmp=0;@tmp>$tmp;++$tmp) { tool_call($tmp[$tmp][0],$tmp[$tmp][1],$tmp[$tmp ][2],$tmp[$tmp][3],$tmp[$tmp][4],$tmp[$tmp][5],$tm p[$tmp][6],$tmp[$tmp][7],$tmp[$tmp][8],$tmp[$tmp][ 9],$tmp[$tmp][10]); }

      would be FAR neater as:

      for (@tmp) {
      tool_call($_[0..10]);
      }
      though even that falls into Perls "default argument" trap - a far better method (for all of Perl) is to not use $_ at all, and extract the arg into a well named my() scalar.

    2. Re:Horrible Code I must debug by Anonymous Coward · · Score: 0

      This is either a bad joke, auto-generated code, or someone is really stupid, and should not be trusted with any programming language.

    3. Re:Horrible Code I must debug by urbanRealist · · Score: 1

      That is one of the funnies posts I've ever read. Thanks for making shitty day worth waking up this morning!

      --
      I've seen a lot of things, but I've never been a witness.
    4. Re:Horrible Code I must debug by andy@petdance.com · · Score: 1

      Using crappy, meaningless variable names is hardly Perl's fault. See my article The world's two worst variable names.

    5. Re:Horrible Code I must debug by Loundry · · Score: 1

      This is either a bad joke, auto-generated code, or someone is really stupid, and should not be trusted with any programming language.

      I only wish. What I posted are snippets production code. I'm guessing from your comment that you don't yet have a lot of experience with programming. I've seen it over and over again (and been responsible for some of it): code does not have to be maintainable to be functional.

      I've taken it upon myself to try and replace every bit of that human's code before I leave, so that I don't leave the person who replaces me in the same position that I inherited. I guess that's the nerd's way of "paying it forward".

      --
      I don't make the rules. I just make fun of them.
  46. My most favoured Perl debugger by qa'lth · · Score: 1

    Runs on X11, works for CGI scripts as well as locally-executed scripts, and is very, very nice.
    just install Devel::ptkdb from CPAN, or here, on the CPAN site.

    It uses Tk and is very much usable over an 11Mbps wifi link, is fast, understands perl objects, hashrefs, etc.

    Best of all, it doesn't impose a monolithic IDE on your development process.

  47. Re:Who Uses Perl Anymore? by Lost+Found · · Score: 1

    Yes, but that is nonsense in this context. Perl isn't aggressively marketed by the world's largest software corporation, piloted by the richest man on earth. Thus a decision to use Perl is much more likely based on experienced merit versus perceived merit.

  48. Perl debugger by Anonymous Coward · · Score: 0

    I hope it's not written in perl

  49. Re:Who Uses Perl Anymore? by Anonymous Coward · · Score: 0

    Perl is the most widely used language in Bioinformatics and hence in life sciences.

  50. Re:Isn't it time to bury Perl? by eyeye · · Score: 1

    I mean, the language is bloated, cryptic, unwieldy and rather slow

    flamebait I know, but have any of you seen the amount of crud that Java projects accumulate these days, unless you know the syntax for the XML files and inheritance hierarchy for all the different MVC/ORM/IOC etc frameworks that get used you are in for a whole load of headaches. If you *dont* use them then you are in for a headache from having to write reams of tiresome code that would just a few short lines in a language such as perl.

    --
    Bush and Blair ate my sig!
  51. eclipse (epic) as a perl ide / debugger by turchinc · · Score: 1

    i used to use komodo or ptkdb or print "something" for perl debugging but recently i have been using epic, the perl IDE for eclipse.
     
    it has a graphical debugger and a heap of other useful features for developing in perl (see the sf.net page for more details...). another advantage: if you need to develop in other languages, there is likely a plugin for them as well, so that you can do everything without leaving your ide (yes: i know about emacs. no: i never did take the time to learn it...)

    :wq

    --

    "i would rather maintain someone else's language than someone else's perl..."

  52. isn't it amazing by boxie · · Score: 1

    It is amazing what people come up with when presented with a problem.

    Our common problem is Perl. It is a fantastic language, but when things go south it *is* one of the more difficult languages to debug.

    My solution (since most of my code runs unattended most of the time) is a nice little "logging" routine. I specify the "logging" level (debug, warnings, errors etc) and only those message get written to the output log.

    This way i can find out where things go wrong. (both code and things that go wrong whilst later on when the code is in production)

    Also liberal use of die() statements in development come in handy!

    --
    A Tale of 2 idle hands
  53. write-once by Anonymous Coward · · Score: 0

    Perl is a write-once language - it is often far easier to rewrite Perl code that doesn't work than to try to understand the cryptic crap most Perl programmers write.

    Personally, I think the author of Perl sat down and thought, "You know, programmers just don't use the shift key enough...". I wore the lettering off of the shift keys in just one three-month Perl project. No joke.

  54. The article has an indentiy crisis by Anonymous Coward · · Score: 0

    TFA's setting PHPSESSID to 2bae32d66becd696d755dd30b38b2f96!
    There's a bug that makes it look like the 1337 Perl site is masquerading as PHP code.
    Obviously that's a bug that needs to be squished.
    +5, Funny
    They must be trying to protect their servers from t3h 1337 h4X0rz from Slashdot.
    (Or fool everything into thinking that they've got a secure edition of PHP, such as PHP 6, which doesn't exist yet.)
    +5, Insightful
    With code this good, no wonder I spend so much^H^H^H^Hlittle time debugging in PHP^H^H^H^HPerl.
    -1, Flamebait
    Disclaimer: I'm not karma whore.
    +1, Extra 'Insightful' modifier
    Karma Total: 10. ;-)

  55. Give me a break! by Loundry · · Score: 1

    Oh, come on! I started my post with this comment: "The worst thing about Perl is its coders. I willfully self-impugn with that statement."

    Of course it's not Perl's fault! It's *always* the coder's fault!

    --
    I don't make the rules. I just make fun of them.
  56. nevermind... by cratermoon · · Score: 1

    On the other hand, you might want to Forget the debugger.

  57. Re:Who Uses Perl Anymore? by kungtotte · · Score: 1

    The new version of http://www.penny-arcade.com/ was built using Ruby (on Rails).

  58. Creating Horrible Code by eelko · · Score: 1

    Once we had to ship some code to a company that took over our developed applications. Little was specified as to how we should deliver the code to them, only that it had to work on their side.

    We started thinking about replacing variable names with randomly created other names, etc etc. The usual.

    The one I liked best was to collect all the comments from the code, shuffle them randomly and stick them back in. And you can create a random-comment generator, which makes life for the Other Developers so wonderful.

      Of course you can do the same with all variable names. The only problem there is that when someone uses the great Perl eval-function (TM) on some strings, it is unsure that the strings contain the correct code. And with modules you need to take care that you 'fix' the right routine names everywhere, in all modules.

      But the best way to create Horrible Code (TM) is of course to start out without specs because your project manager says YouHaveToFinishItSoonBecauseHeHasPromisedIt, find out every other day that the specs have changed without your knowledge or consent, having to publish the unfinished code to a production environment and work on it for two more months because the basic specs of the system turn out to be invalid while some of the customers are already working with the system. No, I am not kidding.

    Guess why I have chosen a new job now...

  59. Perl Debugger by JimPrunier · · Score: 0, Troll

    PERL has got to be one of the most stupid computer languages ever devised. It needs a debugger to step through what is being done but that help comes at a cost of learning the debugger - a PERL derivative. What intelligence cries out for is a language that is written in readable code that is far from the madding crowd of open source meddlers. Reading books about PERL basics tells you that it was invented by happenstance without the slightest guidelines. It uses octal numbering for Pete's sake. Going further with debiugging guides makes understanding exponentially more difficult. A loser follows a loser. Jim

  60. Re:Who Uses Perl Anymore? by Anonymous Coward · · Score: 0