Perl calling subroutine with leading '&' [duplicate]

好久不见. 提交于 2019-12-11 08:53:20

问题


Every now and then I see Perl scripts where subroutines are called with a leading '&'. Is this legacy, or does it give any benefit? As calling the subroutine without the ampersand sign works as well.

sub mysub {
        print "mysub\n"; 

}

mysub;
&mysub;

Thx/Hermann


回答1:


Calling with & is generally a code smell that somebody doesn't know what they're doing and are in a Perl4 mindset. In your specific example, it works exactly the same. However, calling with & disables function prototypes, so advanced users may use it in certain circumstances. You should expect to see a comment why next to the call in that case.



来源:https://stackoverflow.com/questions/21908470/perl-calling-subroutine-with-leading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!