Perl my 函式



描述

此函式宣告 LIST 中的變數在封閉塊中使用詞法作用域。如果指定了多個變數,則所有變數都必須用括號括起來。

語法

以下為此函式的簡單語法 −

my LIST

返回值

此函式不返回值。

示例

以下是顯示其基本用法的示例程式碼 −

#!/usr/bin/perl -w

my $string = "We are the world";
print "$string\n";
myfunction();
print "$string\n";

sub myfunction {
   my $string = "We are the function";
   print "$string\n";
   mysub();
}
sub mysub {
   print "$string\n";
}

執行以上程式碼後,它會產生以下結果 −

We are the world
We are the function
We are the world
We are the world
perl_function_references.htm
廣告
© . All rights reserved.