Created
September 15, 2011 00:44
-
-
Save stevej/1218243 to your computer and use it in GitHub Desktop.
Just a reminder that Perl had both dynamic and static scoping
This file contains 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
$x = 0; | |
sub f { return $x; } | |
sub g { my $x = 1; return f(); } | |
print g()."\n"; | |
# the power of scoping compels you, change global $y! | |
$y = 0; | |
sub f1 { return $y; } | |
sub g1 { local $y = 1; return f1(); } | |
print g1()."\n"; | |
# $ perl ./scoping.pl | |
# 0 | |
# 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can even do this: