Defensive Programming
How can we avoid these problems?
Syntax
Run
perl -c myprog
to check for syntax errors
Permission
Must make sure of this yourself
On Unix, consider chmod a+rx
Semantic
Make sure you pay proper attention to protocol details
The -w flag tells Perl to warn about various things that might be wrong
Place it on the hash-bang line:
#! perl -w
CGI::Carp::carpout
is a function to tell Perl where to send STDERR
Best way is to call
carpout( \*STDOUT );
Termination
The eval function traps any termination and returns the error in
$@
Check its value after calling eval:
if ($@) { warn "An error occurred!"; }
Review
Which of these defensive programming techniques are useful even for non-CGI Perl programs?
[ ] [
Course Contents
] [
Home
] [
Curriculum
]
http://www.keller.com/dbweb/3/solutions.html
Updated
Wednesday, 31-Oct-2001 14:17:39 CST
Copyright © 2006
Dan Keller Technical Services
4500 19th St., San Francisco
California, USA 94114
tel: 415 / 861-4500