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'

In reply to Re: Bug in 'strict'?? by Jouke
in thread Bug in 'strict'?? by Jouke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.