Created
October 25, 2011 22:38
-
-
Save koorchik/1314573 to your computer and use it in GitHub Desktop.
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
#---------------------------------------------------------# | |
# Локализация пакетных переменных | |
our $l = 5; | |
{ | |
local $l = 4; | |
say $l | |
}; | |
say $l; | |
#4 | |
#5 | |
#---------------------------------------------------------# | |
# Локализация переменных с лексической областью видимости | |
my $l = 5; | |
{ | |
local $l = 4; | |
say $l | |
}; | |
say $l; | |
# В результате получим ошибку | |
#Can't localize lexical variable $l at -e line 3. | |
#---------------------------------------------------------# | |
# Но возможна локализация элементов локально | |
# объявленных массивов/хешей | |
my @l = (2,3,5); | |
{ | |
local $l[2] = 4; | |
say $l[2]; | |
}; | |
say $l[2]; | |
#4 | |
#5 | |
#---------------------------------------------------------# | |
# Может быть полезно, например, в такой ситуации | |
{ | |
local $h->{RaiseError}; # no RaiseError | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment