JadeNB has asked for the wisdom of the Perl Monks concerning the following question:
prints nothing, butsub a { print } sub b { local ( $_ ) = @_; goto &a } b("Hi\n");
(changing only goto &a to a(@_)) prints Hi. It's not clear to me that Temporary Values via local() indicates that this is the expected behaviour. Is it happening because dynamic scoping and TCO are incompatible (is that even true?), or is it just an artifact of the guts of Perl, or … other?sub a { print } sub b { local ( $_ ) = @_; a(@_) } b("Hi\n");
UPDATE: Ha, I'm reading the wrong docs; shoulda looked at goto, as lakshmananindia and moritz indicated—thanks! Still, I wonder if there's a reason for this—it seems to me that the combination of dynamic scoping and TCO could be useful.
UPDATE 2: Thanks to anonymonk, I also noticed that I forgot the locals. No more 3 AM posting for me. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: goto escapes local bindings
by moritz (Cardinal) on Aug 03, 2009 at 07:45 UTC | |
|
Re: goto escapes local bindings
by lakshmananindia (Chaplain) on Aug 03, 2009 at 07:45 UTC | |
|
Re: goto escapes local bindings
by Anonymous Monk on Aug 03, 2009 at 07:46 UTC | |
by JadeNB (Chaplain) on Aug 03, 2009 at 07:51 UTC | |
|
Re: goto escapes local bindings
by Anonymous Monk on Aug 03, 2009 at 20:30 UTC |