此函数声明LIST中的变量在包围式块内按词法范围。如果指定了多个变量,则所有变量都必须用括号括起来。
以下是此函数的简单语法-
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-my.html
来源:LearnFk无涯教程网
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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)