in reply to Re: subroutine is confusing
in thread subroutine is confusing
I reckon a good bet, in these circumstances, is to always use the parens.
Good advise but not applicable when using sort as sort only requires the name of the sub to use as a callback whereas with parentheses tells perl to run the sub.
Update: Had parentheses in wrong place ... oops.$ perl -le' my @x = qw[ one two three four ]; sub compare { $a cmp $b } print for sort compare @x; ' four one three two $ perl -le' my @x = qw[ one two three four ]; sub compare { $a cmp $b } print for sort compare() @x; ' Array found where operator expected at -e line 9, at end of line (Missing operator before ?) syntax error at -e line 9, near ") @x" Execution of -e aborted due to compilation errors.
|
|---|