Local variable: Difference between revisions

Content deleted Content added
m Reverted good faith edits by 41.233.16.36; Reverting redundant sentence. (TW)
added info about Perl's “local” operator
Line 17:
 
Note: This is distinct from other usages of the <code>static</code> keyword, which has several different meanings in various other languages.
 
==<code>local</code> in Perl==
 
[[Perl]] has a keyword, <code>local</code>, for “localizing” variables, but in this case, <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> It 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 lexical variables, which are more like the automatic variables discussed above, 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>
 
==References==
<references />
 
 
{{compu-prog-stub}}