Perl子程序与"&"(和号)之间有什么区别

Gil*_*ain 0 perl subroutine

Perl中接下来的两行之间有什么区别:

PopupMsg("Hello");

&PopupMsg("Hello");

...

sub PopupMsg
{
    subroutines code here...
}
Run Code Online (Sandbox Code Playgroud)

请注意,在某些情况下,我必须使用第一行,在某些情况下,第二行,其他方面,我得到一个错误.

Bor*_*din 5

使用&符调用子程序是不好的做法&.只要您使用括号或将符号预先声明为子例程名称,调用就可以正常编译.

当您将子例程作为数据项处理时,例如引用它时,和符号是必需的.

my $sub = \&PopupMsg;
Run Code Online (Sandbox Code Playgroud)