in reply to Re: File::Temp survival and scope created by "do"
in thread File::Temp survival and scope created by "do"
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: File::Temp survival and scope created by "do"
by Eily (Monsignor) on Dec 10, 2018 at 16:54 UTC | |
by haukex (Archbishop) on Dec 10, 2018 at 20:42 UTC | |
by ikegami (Patriarch) on Dec 10, 2018 at 21:54 UTC | |
by Eily (Monsignor) on Dec 11, 2018 at 00:09 UTC | |
by ikegami (Patriarch) on Dec 11, 2018 at 04:14 UTC | |
by Eily (Monsignor) on Dec 10, 2018 at 23:22 UTC | |
by ikegami (Patriarch) on Dec 11, 2018 at 12:46 UTC | |
by haukex (Archbishop) on Dec 11, 2018 at 11:17 UTC | |
by xiaoyafeng (Deacon) on Dec 11, 2018 at 06:32 UTC |