Created
October 22, 2015 15:43
-
-
Save exodist/16c550dc868e17e6d071 to your computer and use it in GitHub Desktop.
Sub::Uplevel vs goto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
package uplevel; | |
use Sub::Uplevel; | |
use Carp qw/cluck/; | |
#line 10 | |
sub a { cluck "XXX" }; | |
sub b { a('a') } | |
sub c { b('b') } | |
sub d { uplevel(1, \&c, 'c') } | |
sub e { d('d') } | |
sub f { e('e') } | |
f('f'); | |
package goto; | |
use Carp qw/cluck/; | |
#line 10 | |
sub a { cluck "XXX" }; | |
sub b { a('a') } | |
sub c { b('b') } | |
sub d { @_ = ('c'); goto &c } | |
sub e { d('d') } | |
sub f { e('e') } | |
f('f'); | |
__END__ | |
XXX at test.pl line 10. | |
uplevel::a("a") called at test.pl line 11 | |
uplevel::b("b") called at test.pl line 12 | |
uplevel::d("d") called at test.pl line 14 <--------- | |
uplevel::e("e") called at test.pl line 15 | |
uplevel::f("f") called at test.pl line 17 | |
XXX at test.pl line 10. | |
goto::a("a") called at test.pl line 11 | |
goto::b("b") called at test.pl line 12 | |
goto::c("c") called at test.pl line 14 <---------- | |
goto::e("e") called at test.pl line 15 | |
goto::f("f") called at test.pl line 17 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment