描述
此函數將 LIST 中指定的變量定義為封閉塊、文件或 eval 語句中的全局變量。它實際上與 my.it 相反。它聲明一個變量在整個範圍內是全局的,而不是創建一個新的同名私有變量。所有其他選項與我的相同;
我們的聲明聲明了一個全局變量,該變量將在其整個詞法範圍內可見,甚至可以跨越包邊界。變量輸入的包是在聲明時確定的,而不是在使用時確定。如果列出了多個值,則列表必須放在括號中。
用法
以下是此函數的簡單語法 -
our EXPR our EXPR TYPE our EXPR:ATTRS our TYPE EXPR:ATTRS
返回值
此函數不返回任何值。
示例
以下是顯示其基本用法的示例代碼 -
#!/usr/bin/perl -w
our $string = "We are the world";
print "$string\n";
myfunction();
print "$string\n";
sub myfunction {
our $string = "We are the function";
print "$string\n";
}
執行上述代碼時,會產生以下結果 -
We are the world We are the function We are the function
相關用法
- Perl oct()用法及代碼示例
- Perl open用法及代碼示例
- Perl ord()用法及代碼示例
- Perl oct用法及代碼示例
- 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 our Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。