M
Mark
I get "Use of uninitialized value in open" the second time through the
loop. However, if I declare $buff before the loop (and not in the
loop), I don't get the error.
Can someone explain what is happening?
use strict;
use warnings;
$| = 1;
#my $buff;
foreach (1..2) {
print "starting iteration $_\n";
my $buff;
open(my $TMPBUF,'>',\$buff) || die "open, $!\n";
print {$TMPBUF} "$_\n";
close($TMPBUF);
# print "buff=>$buff<\n";
}
Output::
starting iteration 1
starting iteration 2
Use of uninitialized value in open at j.pl line 10.
loop. However, if I declare $buff before the loop (and not in the
loop), I don't get the error.
Can someone explain what is happening?
use strict;
use warnings;
$| = 1;
#my $buff;
foreach (1..2) {
print "starting iteration $_\n";
my $buff;
open(my $TMPBUF,'>',\$buff) || die "open, $!\n";
print {$TMPBUF} "$_\n";
close($TMPBUF);
# print "buff=>$buff<\n";
}
Output::
starting iteration 1
starting iteration 2
Use of uninitialized value in open at j.pl line 10.