Content deleted Content added
No edit summary Tags: Reverted possible vandalism |
No edit summary Tag: Reverted |
||
Line 18:
==Local variables in Perl==
[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead ur fat, the <code>local</code> keyword gives a temporary, [[scope (programming)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref>
To understand how it works consider the following code:
|