a few comments on your code:
On Thu, 27 Sep 2012 00:46:13 -0000
> Take a look at the simple script below. $c should never show up,
> right? On FastCGI servers it often does! Try loading it, calling it,
> and hitting F5 enough, and the text in $c gets displayed. Call them
> Phantom, or Zombie, but they live on after the script exits and may
> show up in the next script called. So, what's going on? Well....
> On a server configured for FastCGI, the perl operating system stays
> alive so that it does not need to be reloaded every time a script is
> called, improving performance. Unfortunately, if you are running your
> script on such a server, you have to take some extra precautions.
> Using reset 'a-z'; will clear your lower case variables,
> unfortunately, the upper case version will also clear the
> environmental variables which you may be using. One workaround on
> this is to kill the variables as the script exits, for example:
> reset 'a-z'; reset 'A-Z'; exit;
> There are other ways to do this for sure, but clearing on exit is an
> easy way to upgrade scripts you may already have written and recently
> began to misbehave.
Always add "use strict;" and "use warnings;":
> $a = localtime();
Declare the variable using "my" and don't call it "$a":
> $test_file = 'test.txt';
> open DATA, ">>$test_file" or die "can't open $test_file $!";
1. Use three-args open.
2. Use lexical file handles
3. The *DATA file handle has a special meaning in Perl, and should not
> print DATA $a.'<br>';
> print DATA $c.'<br>';
> close (DATA);
> open DATA, "<$test_file" or die "can't open $test_file $!";
> @new_data = <DATA>;
> close (DATA);
> #output page
> print <<EOF ;
Always use <<'EOF' or <<"EOF" for avoiding ambiguity:
> Content-type: text/html
> <META http-equiv="EXPIRES" CONTENT="0">
> <meta http-equiv="pragma" content="no-cache">
If you're going to interpolate @new_data into a string, you should slurp it
as a string using File::Slurp or whatever.
> $c = 'This line should never show up';
Well, with package-scope variables, no wonder why FastCGI preserves them.
Shlomi Fish http://www.shlomifish.org/
List of Portability Libraries - http://shlom.in/port-libs
Knuth is not God! Typing “God” into Google and pressing “I’m Feeling Lucky”
will not lead you to his homepage.
Please reply to list if it's a mailing list post - http://shlom.in/reply