in reply to Re: cross scope gotos?
in thread cross scope gotos?
which is part of the answer...
But it's not the scoping visibility of the label variable which hinders the jump back to work like you can see in the following example:
my $label; sub jump { goto $label ;# jump back}; sub cont { for $i (0..3) { for $j ("a".."c") { print "$i,$j\t"; $label=NESTED; #jump(); # works goto &jump; # fails } NESTED: } } cont();
It's the point that gotos are only possible to destination within the scope of the call chain.
BUT It may not be used to go into any construct that requires initialization, such as a subroutine or a "foreach" loop.
Since jump() adds a new call frame, there is no more initialization of the old frame needed when jumping back, just closing the new frames.
But with goto &jump the old call frame is replaced and all links to possible labels there!
So jumping back would imply a re-initialization of this frame, which is not possible...
I got it, thanks for discussing it! :)
Cheers Rolf
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: cross scope gotos?
by LanX (Saint) on Apr 06, 2010 at 12:36 UTC | |
by Anonymous Monk on Apr 06, 2010 at 13:20 UTC | |
by LanX (Saint) on Apr 06, 2010 at 13:28 UTC |