As per perldoc perlsub:
The & is optional in modern Perl, as are parentheses if the subroutine has been predeclared.
I notice that a lot of times, people use the fact that you can omit parenthesis when calling Perl subroutines (e.g., randomly quoting from a recent SO answer):
open my $fin, '<', $file;
is as equally valid as
open(my $fin, '<', $file);
What are the main (ideally, technical) reasons to use the second (parenthesis-less) version?
perldoc perlsyn doesn't say anything on the topic other than again mention optionality.
For me, always using the parenthesis are mostly a stylistic choice due to my origins as a C developer; but I'd like to know if I'm missing something out on not using the optional parenthesis-less syntax as a Perl developer.
P.S. I know full well the reasons to prefer the version with parenthesis - e.g. the issues with indirect object notation, or requirement to declare non-builtins before they are used without parenthesis, or issues with precedence visavi or
vs ||
. I'm interested in the opposite.
P.P.S. I'm not greatly interested in answers merely stating "it's better style"/"more readable" without any studies backing the opinion up. I'm interested in either technical reasons to prefer parenthesis omission, or backed up stylistic difference preferences (Please don't confuse "backed up" with "appeal to authority" or "argumentum ad populum" fallacies. A study showing improvement in speed or comprehension of code is proof. "Everyone in Perl commmunity agrees" or "Damien Conway suggests this" without explaining how Damien backs this up is not).
I think the only time that it actually matters, other than style, is for the rarely used &subname
which according to perldoc perlsub:
&NAME; # Makes current @_ visible to called subroutine.
Of course, using parens might make for easier disambiguation in some cases (both for the parser and the future reader), or else not using them might remove noise in others; the degree to which either of those is necessary is probably the primary reason I would ever choose one or the other.