Perl local 函数

描述

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.


语法

以下是此函数的简单语法 −

local LIST

返回值

此函数不返回任何值。


示例

以下是显示其基本用法的示例代码 −

#!/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

❮ Perl 函数参考