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
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution


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


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