Jürgen Exner said:
It has different semantics, so it depends upon what you want/need.
(with a subtext of "you almost never want the semantics that ampersand gives")
Where did you read it?
The above was a rhetorical question, as I recognize that quote
from the Llama book.
You snipped the part after the "or":
if Perl can tell from the syntax that it's a subroutine call
All of my code makes use of that snipped part.
I define my subroutines at the end of my program, after the main code.
I do not declare my subroutines either.
("define" and "declare" mean different things.)
Yet I never use ampersand on subroutine calls.
So how do my programs end up working then?
I make use of the part after the "or"...
.... I always use parenthesis when calling my user-defined subroutines.
Both approaches have "safety" issues.
Using the ampersand may invoke the often unwanted semantics mentioned below.
Using only parenthesis may call a built-in subroutine with the
same name rather than the user-defined subroutine.
You got the wrong idea. Actually several wrong ideas.
1: where if not at the beginning of your script do you define your subs?
You don't do that in the middle of the main body, do you?
I do it at the end.
2: as you wrote correctly the declaration has to be before the
invocation,
.... or you must use parenthesis around the argument list.
while the definition of the sub can be anywhere, even
textually after its invocation
3: the ampersand is not "a thing of the past". It modifies the calling
semantic, such that
a) prototypes are overridden
b) @_ is visible to the called sub
(for details see perldoc perlsub).
If you want that semantic (which IMO is somewhat screwy) then use
ampersands. For normal programs it causes too many unwanted
dependencies, so I advise against using them. It is just easier not
having to deal with them.
Debugging when the ampersand approach is used can be really tricky.
Debugging when the parenthesis approach is used is easy. Just do a
perldoc -f my_func
If it returns docs for my_func(), then choose a different name
for your user-defined subroutine.
So as Jürgen said, it is not a thing of the past.
However, the "when not absolutely needed" part _is_ correct.
The ampersand is absolutely needed if you want the above special
treatment of the sub's argument list or if you insist on using
the same name as a built-in.
It is rare to want or need the arg special treatment, and I do not
recommend reusing the name of a built-in Perl function.
So if you follow a simple rule, you won't have much to worry about:
Never use ampersand on subroutine calls, always use parenthesis
on (user-defined) subroutine calls (but watch out for name collisions)