问题
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