Skip to Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

use strict

use strict;         # Install all three strictures.use strict "vars";  # Variables must be predeclared.
use strict "refs";  # Can't use symbolic references.
use strict "subs";  # Bareword strings must be quoted.
use strict;         # Install all…
no strict "vars";   # …then renege on one.

This lexically scoped pragma changes some basic rules about what Perl considers to be legal code. Sometimes these restrictions seem too strict for casual programming, such as when you're just trying to whip up a five-line filter program. The larger your program, the more you need to be strict about it.

Currently, there are three possible things to be strict about: subs, vars, and refs. If no import list is supplied, all three restrictions are assumed.

strict 'refs'

This generates a run-time error if you use symbolic references, intentionally or otherwise. See Chapter 8 for more about these.

use strict 'refs';$ref = \$foo;       # Store "real" (hard) reference.
print $$ref;        # Dereferencing is ok.
$ref = "foo";       # Store name of global (package) variable.
print $$ref;        # WRONG, run-time error under strict refs.

Symbolic references are suspect for various reasons. It's surprisingly easy for even well-meaning programmers to invoke them accidentally; strict 'refs' guards against that. Unlike real references, symbolic references can only refer to global variables. They aren't reference-counted. And there's often a better way to do what you're doing: instead of referencing a symbol in a global symbol table, use a hash as its ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata