X hits on this document

PDF document

Running and Debugging Perl - page 5 / 30

68 views

0 shares

0 downloads

0 comments

5 / 30

Running and Debugging Perl

Since perl treats everything between print<<EOF; and the terminator EOF as plain text, it only takes a broken terminator for perl to interpret the rest of your program as nothing more than a long string of characters.

Missing Comma

If you forget a comma where there should be one, you'll almost always get the 'Scalar found where operator expected' message. This is because Perl is trying to connect two parts of a statement together and can't work out how to do it.

Brackets Around Conditions

You need brackets around the conditions of if, for, while, and their English negatives unless, until. However, you don't need brackets around the conditions when using them as statement modifiers.

Barewords

If an error message contains the word 'bareword', it means that Perl couldn't work out what a word was supposed to be. Was it a scalar variable and you forgot the type symbol? Was it a filehandle used in a funny context? Was it an operator or subroutine name you spelled wrong? For example, if we run:

#!/usr/bin/perl #bareword.plx use warnings; use strict;

Hello;

perl will tell us:

>perl bareword.plx Bareword "Hello" not allowed while "strict subs" in use at bareword.plx line 5. Execution of braces.plx aborted due to compilation errors. >

We'll see more in the section on barewords in use strict below.

Diagnostic Modules

Hopefully, I've already drummed into you the importance of writing use strict and use warnings in your code. Now it's time to explain what those, and other modules like them, actually do.

As we'll see in the next chapter, use introduces an external module, while warnings and strict are both standard Perl modules that come with the Perl distribution. They're just ordinary Perl code. The special thing about them is that they fiddle with internal Perl variables, which will alter the behavior of the perl interpreter.

Strictly speaking these are pragmas (or, for the linguistically inclined, pragmata) rather than modules. These have all lower-case names and are particularly concerned with altering the operation of perl itself, rather than providing you with ready-made code.

283

Document info
Document views68
Page views68
Page last viewedSat Dec 03 04:42:44 UTC 2016
Pages30
Paragraphs723
Words10014

Comments