Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Last active June 21, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitrySoshnikov/8b92809df8545319267ffeeb37108ba5 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/8b92809df8545319267ffeeb37108ba5 to your computer and use it in GitHub Desktop.
# 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