|
|
Use of uninitialized value in open
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.
|
|
0
|
|
|
|
Reply
|
Mark
|
4/5/2011 10:27:54 PM |
|
On 2011-04-05 22:27, Mark <google@markginsburg.com> wrote:
> 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?
[...]
> foreach (1..2) {
> print "starting iteration $_\n";
> my $buff;
> open(my $TMPBUF,'>',\$buff) || die "open, $!\n";
[...]
> }
>
> Output::
> starting iteration 1
> starting iteration 2
> Use of uninitialized value in open at j.pl line 10.
I get this warning with perl 5.8.8 but not with 5.10.1, so I guess it's
a bug which was fixed in perl 5.10.
As a workaround you can just assign an empty string to $buff:
my $buff = "";
hp
|
|
0
|
|
|
|
Reply
|
Peter
|
4/6/2011 7:26:56 AM
|
|
Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> On 2011-04-05 22:27, Mark <google@markginsburg.com> wrote:
>> 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?
> [...]
>> foreach (1..2) {
>> print "starting iteration $_\n";
>> my $buff;
>> open(my $TMPBUF,'>',\$buff) || die "open, $!\n";
> [...]
>> }
>>
>> Output::
>> starting iteration 1
>> starting iteration 2
>> Use of uninitialized value in open at j.pl line 10.
>
> I get this warning with perl 5.8.8 but not with 5.10.1, so I guess it's
> a bug which was fixed in perl 5.10.
I get it with 5.10.0, so it must have been 5.10.1 that fixed it...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
|
|
0
|
|
|
|
Reply
|
Tad
|
4/6/2011 12:22:01 PM
|
|
|
2 Replies
414 Views
(page loaded in 0.059 seconds)
|
|
|
|
|
|
|
|
|