My understanding was using ' & ' was best style practice
In "modern" Perl, that is no longer the case. Calling a sub with & disables prototype checking, and also calling a sub as &foo; leaves @_ unmodified. Since both of these behaviors fall in the "one should only do this if one knows what one is doing" category, calling subs without the & is generally recommended (unless one knows what one is doing :-) ). From perlsub (emphasis mine):
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. See perlref for more about all that.
Subroutines may be called recursively. If a subroutine is called using the & form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.
&foo(1,2,3); # pass three arguments
foo(1,2,3); # the same
foo(); # pass a null list
&foo(); # the same
&foo; # foo() get current args, like foo(@_) !!
foo; # like foo() IFF sub foo predeclared, else "foo"
Not only does the & form make the argument list optional, it also disables any prototype checking on arguments you do provide. This is partly for historical reasons, and partly for having a convenient way to cheat if you know what you're doing. See Prototypes below.
Update: For even more, see "Pitfalls and Misfeatures" in Modern Perl.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Thanks for the response haukex. Will update my sub calls, the examples provided by perlsub make this easier to understand.
| [reply] [Watch: Dir/Any] |
The document perlsub appears to say that the & form is always optional. However, it then specifies a few special cases where it is required. The practice of using the & only when necessary has the advantage of alerting human readers that special argument handling is intended. Casual use of the & form for calling subroutines which specify signatures could lead to subtle errors.
| [reply] [Watch: Dir/Any] |
Thank you very much for the response Bill.
| [reply] [Watch: Dir/Any] |