无涯教程-Perl - local函数

67 阅读1分钟

描述

此函数将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

参考链接

www.learnfk.com/perl/perl-l…