On Wed, 13 Apr 2011 16:07:47 -0700, sono-io wrote: > Hello, > > I read somewhere that it's bad practice anymore to call a subroutine > like this: > > &subroutine(); > > I've also read where it's faster to call a sub like this: > &subroutine; > > than it is to call like this: > subroutine(); > > Is this true? I searched but I can't find a good recent discussion of > this. What is the best (preferred) way to call subroutines today?
It is better to call them as subroutine() provided that you don't define a subroutine with the same name as a Perl builtin. It's better to learn the names of the Perl builtins than to give up and always use &subroutine. The builtins are all listed in perlfunc. It's actually not that hard to get them. The only one that people habitually collide with is log(). If you're worried about the speed overhead of one vs the other then either you are worried about the wrong thing or you have bigger problems. Worry about speed only when (a) you've determined that your code is too slow, and then (b) you've profiled it to find out where the bottleneck is (hint: it's not likely to be in subroutine call overhead). -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 http://www.oreillyschool.com/courses/perl3/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/