local (Perl function)

The built-in function 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"

If a variable of the same name exists outside of the current scope, creates a new variable and ignores/preserves the older variable. Query: is there a way to access the older variable from inside this scope? The older variable is once again accessible when execution leaves 's defined scope.

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

On the other hand, variable references (e.g *varname) can be declared within but not within.

Examples

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