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

