描述
此函數將 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 map用法及代碼示例
- Perl m用法及代碼示例
- Perl sin()用法及代碼示例
- Perl abs()用法及代碼示例
- Perl kill用法及代碼示例
- Perl chop()用法及代碼示例
- Perl wantarray用法及代碼示例
- Perl gmtime用法及代碼示例
- Perl exists()用法及代碼示例
- Perl split用法及代碼示例
- Perl localtime用法及代碼示例
- Perl delete()用法及代碼示例
- Perl undef用法及代碼示例
- Perl reset()用法及代碼示例
注:本文由純淨天空篩選整理自 Perl my Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。