in reply to Re^2: Printing an element of a list not an array
in thread Printing an element of a list not an array
This is because when using print or say, there is ambiguity in what you're passing. Without the parens:
perl -w -E 'say (localtime)[1]' say (...) interpreted as function at -e line 1.
say like print are both functions. perl just makes it convenient that you can omit a function's parens in most situations. say believes that the opening parens belongs to itself, like this: say( localtime )[1] ;, which is wrong. So if you look at it like this: say( (localtime)[1] );, it may become clearer as to what's happening. In most other cases, you can eliminate the parens:
my $x = (localtime)[1];
or
return (localtime)[1];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Printing an element of a list not an array
by raghuprasad241 (Beadle) on Aug 25, 2016 at 15:57 UTC |