Interesting...
So somehow do blocks aren't blocks either?
I'm pretty sure a do BLOCK has its own lexical scope:
$ perl -wMstrict -le 'my $x="A"; do { print $x; my $x="B"; print $x }; print $x' A B A $ perl -wMstrict -le 'do { my $x="A" }; print $x' Global symbol "$x" requires explicit package name (did you forget to d +eclare "my $x"?) at -e line 1. Execution of -e aborted due to compilation errors.
But it seems to me like this might have something to do with a do block being able to return a value:
$ perl -wMstrict -le 'sub Foo::DESTROY {print "BLAM"}; print "A"; do { my $x = bless {}, "Foo" }; print "B"' A B BLAM $ perl -wMstrict -le 'sub Foo::DESTROY {print "BLAM"}; print "A"; do { my $x = bless {}, "Foo"; 1 }; print "B"' A BLAM B
Although I don't know why do { my $x = bless {}, "Foo" } vs. do { bless {}, "Foo" } makes a difference either. Seems strange to me.
In reply to Re^2: File::Temp survival and scope created by "do"
by haukex
in thread File::Temp survival and scope created by "do"
by vr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |