spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / perl / mysqlperl / chap3 / 3 To page 1To page 2current pageTo page 4To page 5To page 6
[previous][next]
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Improving Performance with mod_perl

When you initialize a variable, make sure it's initialized every time your script executes. The following bit of code sets $x to 1, but only if some_test() succeeds:

use vars qw($x);
$x = 1 if some_test ();

The problem is that $x remains set to 1 even if some_test() fails on every subsequent invocation of the script. Suppose what some_test() does is check a user-supplied password and return true if the password is okay. After $x gets set, it remains set, even if the next person to come along provides an incorrect password! The following code handles the situation properly:

use vars qw($x);
$x = 0;
$x = 1 if some_test ();

So does this:

use vars qw($x);
$x = some_test () ? 1 : 0;

The basic principle here is that you don't want to start making decisions based on variable values until you know they've been initialized properly.

When you're trying to determine the cause of problems due to shared script environments, you may find it useful to stop Apache and restart it using httpd -X. The -X option tells Apache to run as a single process rather than in the usual parent-children configuration. That makes shared-environment problems show up more quickly. (You should do this only on a development server, not a production server.)

home / programming / perl / mysqlperl / chap3 / 3 To page 1To page 2current pageTo page 4To page 5To page 6
[previous][next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: July 13, 2001
Revised: July 13, 2001


URL: http://webreference.com/programming/perl/mysqlperl/chap3/3/3.html