Jouke has asked for the wisdom of the Perl Monks concerning the following question:

After carefully considering all comments to my question of yesterday about Bug in 'strict'??, I decided that it probably had nothing to do with Perl, Strict or whatever, but that it just had to be a bug in the WNserver (not VN server...). I decided to give it up, put the code inside a 'no strict' block, and used some of the side-remarks that were made.

One of these remarks was the one from tye about my 'not so pretty regex', which I wholeheartedly admit. I'm certainly not a regex wizard and consider that one of my big flaws.
So I tried out his suggested regex and reran the code. It worked (of course, why did I doubt it in the first place...maybe because it looked so simple). It then occurred to me that maybe the strange behaviour might have disappeared (better regex....better code....better behaviour), so I commented out the 'no strict' part, and voila! The whole damn thing worked like a charm!

But if something doesn't work in the first place, and does in the second, I always want to know why! And I simply don't know. Does anyone have a reasonable explanation for the fact that the following code does work, and the previous code (see Bug in 'strict'?? doesn't? I left the last few lines out because I had to use the CGI::upload method, and didn't in the first piece of code...

This runs on a Debian Linux 2.2.19 machine with Perl 5.005_03, with WN 2.2.9 as webserver. The old code worked fine from the commandline, but when ran as CGI script under WN, the described behaviour occured. I checked to see if the perl-version used for the CGI execution was the same as the one I used when I ran it from the commandline...both 5.005_03.
#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); $|=1; # Don't buffer the output my $buffer; #print out the correct content-type print "Content-type: text/html\n\n"; # start with nice html-tags print "<html><body>"; # new CGI object my $req = CGI->new; #retrieve the value of the selected filename my $filename = $req->param("filename"); # get only the filename (not the entire path) # and if it doesn't match, give $localfilename a silly value my $localfilename = $filename =~ m/([^\Q$CGI::SL\E]+)$/ ? $1 : "ASilly +Value"; # print out $localfilename to see if it has the correct value print "$localfilename<br>\n"; # open $localfilename for output (and here it fails, # with the $localfilename as an empty string) open(FILE, ">$localfilename") || print "Could not open $localfilename for output: $!<br>\n"; # # Left the upload part out here... # close(FILE); print "File saved as $localfilename (original filename=$filename)<br>\ +n"; print "</body></html>\n";


Jouke Visser, Perl 'Adept'