Perl local Function



This function sets the variables in LIST to be local to the current execution block. If more than one value is specified, you must use parentheses to define the list.

Note that local creates a local copy of a variable, which then goes out of scope when the enclosing block terminates. The localized value is then used whenever it is accessed, including any subroutines and formats used during that block.


Following is the simple syntax for this function −

local LIST

Return Value

This function does not return any value.


Following is the example code showing its basic usage −

#!/usr/bin/perl -w

local $foo;			      # make $foo dynamically local
local (@wid, %get);		# make list of variables local
local $foo = "flurp";	  # make $foo dynamic, and init it
local @oof = @bar;		# make @oof dynamic, and init it