in reply to Bug in 'strict'??

OK, so here's for the people who think there's a problem with the regex (there isn't): this is a version which checks if the thing matches. If it doesn't, it gets a silly value...

After the assignment of the $2 to $localfilename, I print out the value of $localfilename, and yet it prints out the errormessage with an empty string for $localfilename...

#!/usr/bin/perl -w use strict; use CGI; $|=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/(.*?$CGI::SL)*(.*)(?=$)/ ? $2 : "AS +illyValue"; # print out $localfilename to see if it has the correct value print $localfilename; # open $localfilename for output (and here it fails, with the $localfi +lename as an empty string) open(FILE, ">$localfilename") || print "Could not open $localfilename +for output: $!<br>\n"; # it doesn't even get here...so ignore please... while (my $bytesread = read($filename,$buffer,1024)) { print FILE $buffer; } close(FILE); print "File saved as $localfilename (original filename=$filename)<br>" +; print "</body></html>";


Jouke Visser, Perl 'Adept'

Replies are listed 'Best First'.
(tye)Re2: Bug in 'strict'??
by tye (Sage) on Apr 05, 2001 at 19:40 UTC

    I'll go w a y out on a limb and blame this on a bug in the regex engine.

    m/(.*?$CGI::SL)*(.*)(?=$)/ is pretty, um, well, isn't pretty. ;) m/([^$CGI::SL]+)$/ is going to give the regex engine much fewer fits. See if that fixes things (that requires that you use $1 instead of $2 or just use my( $localfilename )= m/... instead).

            - tye (but my friends call me "Tye")