Practical mod_perl / HTML Version / books


previous page: 22.3.5. rwrite returned -1page up: HTML Version of the booknext page: 22.3.7. Use of uninitialized value at (eval 80) line 12

22.3.6. Global symbol "$foo" requires explicit package name


Search







modperlbook.org


 HTML Version


 PDF Version


 Download Code


 Table of Contents


 Errata


 mod_perl2 User's Guide


 Sitemap





Add to Google



Creative Commons License


Written by
Eric Cholet (Logilune)
and Stas Bekman (StasoSphere).

Hosted by ibiblio.org.




























This error message is printed when a nondeclared variable is used in the code running under the strict pragma. For example, consider the short script below, which contains a use strict; pragma and then shamelessly violates it:

#!/usr/bin/perl -w
use strict;
print "Content-type: text/html\n\n";
print "Hello $username";

Since Perl will insist that all variables are defined before being used, the program will not run and will print the error:

Global symbol "$username" requires 
explicit package name at /home/httpd/perl/tmp.pl line 4.

Moreover, in certain situations (e.g., when SIG{_ _DIE_ _} is set to Carp::confess( )) the entire script is printed to the error_log file as code that the server has tried to evaluate, so if this script is run repeatedly, the error_log file will grow very fast and you may run out of disk space.

This problem can easily be avoided by always declaring variables before using them. Here is the fixed version of our example:

#!/usr/bin/perl -w
use strict;
my $username = '';
print "Content-type: text/html\n\n";
print "Hello $username";

 

Continue to:

  • prev: 22.3.5. rwrite returned -1
  • Table of Contents
  • next: 22.3.7. Use of uninitialized value at (eval 80) line 12

Tags

mod_perl, modperl, Apache, perl, cgi, html, mod_perl, e-commerce, scalability, free, open source, OSS, apache, squid, high availability, modperl, linux, unix, Web, www, mod_perl, webserver, admin, apache, book, webmaster, tools, modperl, guide, docs, documentation, help, mod_perl, perl, information, apache, script, errata, eric cholet, perl, apache, mod-perl, stas bekman, mod_perl, cool, perl, Apache, performance, speed, choice




Other projects to check out: meta-religion.com is for those interested in Religious, Spiritual and Esoteric Phenomena. i-want-a-better.com is a community of people discussing what they would like to be improved in their lives and things they use and interact with. You may also want to find a healer in your area or read articles on variety of topics.






TOP
previous page: 22.3.5. rwrite returned -1page up: HTML Version of the booknext page: 22.3.7. Use of uninitialized value at (eval 80) line 12

© 2007 StasoSphere

[ Privacy Policy ] [ Terms of Use ] [ About Authors ] [ Search ]

Last modified Wed May 7 06:27:44 2008