good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hello fireblood,
> I've always used a leading ampersand when calling &my_function and have never noticed a problem. Me too I was used to code this way, even if discouraged many times by other monks. I knew the eventual pitfalls and all differences between the two syntax. I always used &my_func( 42 ) to highlight that sub was defined in the current file and not coming from an external module ( update: I found this very useful in my first years of programming, when the whole mess of internal functions, local and imported subs was difficult to distinguish at glance ). Many perl programmers hate this syntax, telling you to avoid it: this is not true. The & is optional > A subroutine may be called using an explicit & prefix. The & is optional in modern Perl, as are parentheses if the subroutine has been predeclared. The & is not optional when just naming the subroutine, such as when it's used as an argument to defined() or undef(). Nor is it optional when you want to do an indirect subroutine call with a subroutine name or reference using the &$subref() or &{$subref}() constructs, although the $subref->() notation solves that problem. The above quote from perlsub states it clearly and tell us even more: you must know this syntax because sometimes it must be used. So, imho, you have not to avoid it but you have to be aware of what it implies and you got good answers about it. Extending a bit what perlsub says you can have the following:
L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. In reply to Re: why avoid & on function call -- defending & syntax
by Discipulus
|
|