Running (and Debugging) the Script

Now that we’ve made hello.plx executable by its owner, let’s try running it again:

[jbc@andros jbc]$ hello.plx
Hello, world!

Congratulations! You’ve just run your first Perl script.

The Joy of Debugging

What if your script didn’t run, though, but instead died with some sort of error message? Or what if it successfully ran, but didn’t produce the output you were expecting? Then you get to experience the joy of debugging.

You’re going to be experiencing a lot of this particular joy. As a novice programmer, the bulk of your time is going to be spent in the debugging phase: tracking down and squashing the silly mistakes that keep your script from running as you intended. (Actually, my understanding from the experienced programmers I know is that they, too, spend a good chunk of their time debugging.)

Sometimes the mistake is obvious: you left off a semicolon, or the closing quotation mark in a quoted string. Other times the mistake is maddeningly obscure (at least until you identify it, at which point it, too, will become obvious): you gave the wrong arguments to a function, or were confused about some aspect of how Perl behaves.

Debugging is a specialized skill, and it takes practice to get good at it. It’s somewhat like car repair. An experienced mechanic can ask a few questions, listen to the engine for a second, and immediately tell you what’s wrong with your car and what it will take to fix it. Meanwhile, a novice mechanic will be pulling apart ...

Get Perl for Web Site Management now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.