Reputation: 1
Why does this code not work:
my $file_handle = $cgi->upload('file');
open my $OUTFILE_FOTO, '>>', "image/$new_file.$extension";
while (<$file_handle>) {
print OUTFILE_FOTO $_;
}
close($file_handle);
close(OUTFILE_FOTO);
but this code does work:
my $file_handle = $cgi->upload('file');
open( OUTFILE_FOTO, '>>', "image/$new_file.$extension" );
while (<$file_handle>) {
print OUTFILE_FOTO $_;
}
close($file_handle);
close(OUTFILE_FOTO);
Upvotes: 0
Views: 55
Reputation: 902
This should work now . You have created a file handle variable when you see my $OUTFILE_FOTO and this is one of the way to implement perl best practises. But you have provided Bareword - OUTFILE_FOTO in the program .You can try to avoid these errors by using use strict; and use warnings;
my $file_handle = $cgi->upload('file');
open my $OUTFILE_FOTO, '>>', "image/$new_file.$extension";
while (<$file_handle>) {
print $OUTFILE_FOTO $_;
}
close($file_handle);
close($OUTFILE_FOTO);
Upvotes: 1
Reputation: 5290
In the first example, you're declaring and assigning a scalar $OUTFILE_FOTO
, but you're referring to it later as if it were a bareword OUTFILE_FOTO
. Prepend a $
to it in theprint
and the close
.
Upvotes: 2