For function calls (i.e. non-OO) the parentheses are sometimes necessary. I can never remember the exact formulations - depends very much on whether strict subs are enabled, and on prototypes. For function calls, best to always include the parentheses, unless it's a constant sub, or you are sure that the sub has been defined with an empty prototype. [emphases added]
Unfortunately, there is a happy little cluster of corner cases associated with the => 'fat comma' operator (see perlop) that are not affected by (or perhaps I should say, that interact in a complex way with) prototyping or strictures.
In the example below, FOO() and 'FOO' (quoted string) are never surprising, but try commenting out successive hash elements from right to left. Try replacing +FOO with !FOO or -FOO instead. Replacing the
use constant FOO => 'foo';
statement with the prototyped function
sub FOO () { 'foo' }
(which is essentially what constant creates for you) makes no difference.
Happy debugging!
>perl -wMstrict -le "use constant FOO => 'foo'; ;; my %hash = ( FOO() => 'ok', FOO => 'oops', +FOO => 'huh?', 'FOO' => 'yes', ); ;; use Data::Dump; dd \%hash; " { foo => "ok", FOO => "yes" }
In reply to Re^2: Any differences between method and method()?
by AnomalousMonk
in thread Any differences between method and method()?
by sophate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |