http://www.perlmonks.org?node_id=11121054


in reply to Re: rename file
in thread rename file

Update - added $ to lexical file handle I added to the script.

I'm not sure if the quotation applies to the
    open ( $UPLOADFILE, ">", $upload_dir/$fileto" ) or die "$!";
statement or not, but if it does, please be aware that a sigil does not a lexical make.

Strictures are not enabled in the code here, so $UPLOADFILE just autovivifies a package-global scalar filehandle where UPLOADFILE would have been a package-global bareword filehandle. For a true lexical, use my:
    open ( my $UPLOADFILE, ">", $upload_dir/$fileto" ) or die "$!";
Of course, the script in question is short enough that lexical-versus-global filehandle won't make any practical difference.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: rename file
by perlfan (Vicar) on Aug 24, 2020 at 19:35 UTC
    Thanks, fixed. Oversight.

      You can't have run the code you posted:

      perl -c xx.pl [Thu Sep 3 09:15:03 2020] xx.pl: String found where operator expected + at xx.pl line 16, near "$fileto" ) or die "" [Thu Sep 3 09:15:03 2020] xx.pl: (Missing operator before " ) or +die "?) [Thu Sep 3 09:15:03 2020] xx.pl: Scalar found where operator expected + at xx.pl line 16, near "" ) or die "$!" [Thu Sep 3 09:15:03 2020] xx.pl: (Missing operator before $!?) [Thu Sep 3 09:15:03 2020] xx.pl: String found where operator expected + at xx.pl line 16, at end of line [Thu Sep 3 09:15:03 2020] xx.pl: (Missing semicolon on previous l +ine?) Status: 500 Content-type: text/html <h1>Software error:</h1> <pre>syntax error at xx.pl line 16, near &quot;$fileto&quot; ) or die +&quot;&quot; Can't find string terminator '&quot;' anywhere before EOF at xx.pl lin +e 16. </pre> <p> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. </p> [Thu Sep 3 09:15:03 2020] xx.pl: syntax error at xx.pl line 16, near +"$fileto" ) or die "" [Thu Sep 3 09:15:03 2020] xx.pl: Can't find string terminator '"' any +where before EOF at xx.pl line 16.