in reply to Re: Any differences between method and method()?
in thread Any differences between method and method()?
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" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Any differences between method and method()? (=>)
by tye (Sage) on Aug 18, 2012 at 18:15 UTC | |
by AnomalousMonk (Archbishop) on Aug 18, 2012 at 19:43 UTC | |
by sophate (Beadle) on Aug 19, 2012 at 04:32 UTC | |
by AnomalousMonk (Archbishop) on Aug 19, 2012 at 05:11 UTC | |
by Anonymous Monk on Aug 19, 2012 at 04:38 UTC | |
|
Re^3: Any differences between method and method()?
by tobyink (Canon) on Aug 18, 2012 at 21:13 UTC | |
by AnomalousMonk (Archbishop) on Aug 19, 2012 at 05:18 UTC |