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.