X hits on this document

PDF document

Running and Debugging Perl - page 12 / 30

79 views

0 shares

0 downloads

0 comments

12 / 30

Chapter 9

when you meant

my ($foo, $bar) = @_;

Remember that "my", "our", and "local" bind tighter than comma.

>

This is helpful when you're debugging but remember that when use diagnostics is seen, the entirety of the perldiag page has to be read into memory, which takes up some time. It's a good idea to use it when writing a program and then remove it when you're done.

Alternatively, there's a standalone program called splain, which explains Perl's warnings and error messages in the same way. Simply collect up the output of your program and paste it to splain. If you're going to use a pipe, remember that warnings end up on standard error, so you'll have to say perl myprogram.plx | 2>&1 | splain to feed standard error there, too. Note that splain won't work on Windows.

Perl Command Line Switches

All of our programs so far have started with this line, the 'shebang' line:

#!/usr/bin/perl

and we've called our program by saying:

>perl program.plx

or possibly on UNIX with:

>./program.plx

The primary purpose of that first line is to tell UNIX what to do with the file. If we say ./program.plx, this just says 'run the file program.plx', it's the 'shebang' line that says how it should be run. It should be passed to the file /usr/bin/perl, which is where the Perl interpreter will usually live.

However, that's not all it does, and it isn't just for UNIX: Perl reads this line itself and looks for any additional text, in the form of switches, which notify Perl of any special behavior it should turn on when processing the file. If we call the Perl interpreter directly on the command line, by saying perl program.plx, we can also specify some switches before Perl even starts looking at the file in question.

Switches all start with a minus sign and an alphanumeric character, and must be placed after perl but before the name of the program to be run. For instance, the switch -w, which is roughly equivalent to use warnings; can be specified in the file, like this:

#!/usr/bin/perl -w

  • #

    program.plx

...

290

Document info
Document views79
Page views79
Page last viewedTue Dec 06 15:04:53 UTC 2016
Pages30
Paragraphs723
Words10014

Comments