Actually you can call a sub like so: sub_name()
Behold the difference in the output of the following snippet
print "Now testing with the ampersand\n";
&ersand('arg1', 'arg2');
print "Now testing with the ampersand, but with 'blank' arguments\n";
&ersand_blank_arg;
print "Now testing without the ampersand\n";
no_ampersand('arg1', 'arg2');
sub ampersand {
&two;
}
sub ampersand_blank_arg {
&two();
}
sub no_ampersand {
two();
}
sub two {
print "@_\n";
}
__OUTPUT___
Now testing with the ampersand
arg1 arg2
Now testing with the ampersand, but with 'blank' arguments
Now testing without the ampersand
The side effect obviously visible with using the ampersand is that it passes the @_ from the sub that called it. And of course, this could easily be thwarted by just putting the empty parens behind the sub name (as demonstrated by ampersand_blank_arg). But I also read on this site ((tye)Re: A question of style) that using the ampersand screws with prototypes.
In the beginning, I used them all the time. Then I pulled my hair out for about a week because I accidentally happened upon the @_ problem. I then started to put the empty parens behind them. But I'm human. I forgot sometimes and I'd kick my self everytime I found one that I missed. Then I found out that you don't need the ampersand if you use the parens and if you forget the parens, you get a bareword error. I love it when Perl tells me I've screwed up. |