Perl 本地函数



描述

此函数将 LIST 中的变量设置为此当前执行块的本地变量。如果指定的值超过一个,则必须使用括号定义列表。

注意,local 会创建变量的一个本地副本,然后在外围块结束时退出作用域。本地化值会在其被访问到时使用,包括在此块期间使用的任何子例程和格式。

语法

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

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_function_references.htm
广告
© . All rights reserved.