From: Vincent Pit Date: Thu, 15 Apr 2010 22:44:05 +0000 (+0200) Subject: A better explaination of how string symbols work X-Git-Tag: rt55593~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=3ccbf65d886255fab86d078e7807d78c576290f3;p=perl%2Fmodules%2FScope-Upper.git A better explaination of how string symbols work --- diff --git a/lib/Scope/Upper.pm b/lib/Scope/Upper.pm index 51cc4c4..91219ff 100644 --- a/lib/Scope/Upper.pm +++ b/lib/Scope/Upper.pm @@ -144,11 +144,23 @@ will set C<$x> to a reference to the string C<'foo'>. Other sigils (C<'@'>, C<'%'>, C<'&'> and C<'*'>) require C<$value> to be a reference of the corresponding type. When the symbol is given by a string, it is resolved when the actual localization takes place and not when C is called. -This means that +Thus, if the symbol name is not qualified, it will refer to the variable in the package where the localization actually takes place and not in the one where the C call was compiled. +For example, + + { + package Scope; + sub new { localize '$tag', $_[0] => UP } + } - sub tag { localize '$x', $_[0] => UP } + { + package Tool; + { + Scope->new; + ... + } + } -will localize in the caller's namespace. +will localize C<$Tool::tag> and not C<$Scope::tag>. =back