local (Perl function)

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Revision as of 17:46, 7 April 2006 by Woozle (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The built-in function local() in Perl creates a variable that is local to the current scope and any functions called from within that scope. That is, it is defined:

  • within the current set of curly braces {}
  • within any further curly braces that are within that current set (as one would expect)
  • within any functions called from within the current set of curly braces (or from within any others nested inside that); this is called "dynamic scoping"

local() is very similar to my(), except that my() does not do dynamic scoping. my() is generally recommended over local(). (You may hear the saying "Don't use local()" from experienced Perl programmers.)

Examples

  • local($avar,$anothervar);
  • local($arg1,$arg2) = @_;
  • local(%hashvar);
  • local %anotherhash;
  • local $justonevar;
  • local @anArray;