Last active
June 21, 2017 22:24
-
-
Save DmitrySoshnikov/8b92809df8545319267ffeeb37108ba5 to your computer and use it in GitHub Desktop.
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
# Perl example of static and dynamic scopes | |
$x = 10; | |
sub print_x { | |
print $x; | |
} | |
sub static { | |
my $x = 20; # doesn't affect | |
print_x(); # 10, not 20 | |
} | |
static(); | |
sub dynamic { | |
local $x = 20; # affects! | |
print_x(); # 20, not 10! | |
} | |
dynamic(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment