|
|
Thursday, 21 November 2024 |
|
2. Turning on debugging information !
Once you succeed with the HelloWorld example,
you can make your life much easier by using some good practices, namely the
following lines should appear in all your scripts !
#!/usr/local/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
...
print header();
|
ad "#!/usr/local/bin/perl -w"
The "-w" turns on warning messages. While writing your script this can be
very useful to avoid common
mistakes and problems. It will also warn you about possible logical problems
like uninitialized variables redining variables in a different scope etc.
Once your script is up and running you might want to consider to turn off
the warning flag off by removing the "-w".
ad "use strict;"
The strict pragma tells the interpreter that you will declare all
variables before you can use then, eg:
or
my ($var1,$var2,$var3);
$var1 = "Some Text";
$var2 = "a few more characters";
$var3 = $var1 . $var2;
|
This can be very, very helpful to avoid typos in variable names which can
be really difficult to trace down otherwise !
ad "CGI::Carp qw(fatalsToBrowser)":
fatalsToBrowser: This will send error messages which may occur while executing your
script back to the browser, usually telling the reason for failure and also the line
where the error occured. IF you don't use this feature you will only get
the unspecifiic Web-server error message 500, "Internal Server Error"
!
For more information on the CGI::Carp
module see:
http://www.perldoc.com/perl5.6/lib/CGI/Carp.html
|