It's not ambiguous.
Something like:
is ambiguous---it could beprint (1,2)[0];
or(print(1,2))[0];
Perl's not sure which you mean, so it issues a warning (if you have warnings enabled), and arbitrarily chooses the second.print((1,2))[0];
Now this is a little bit silly, since the second interpretation is a syntax error, and you can argue that Perl should be smarter about this, but it's not, so you have to be more explicit.
Running with warnings on will help you catch errors like this more easily; if you don't understand them, sending them to splain will help:
$ perl -we'print (1,2)[0];' 2>&1 |splain print (...) interpreted as function at -e line 1 (#1) (W syntax) You've run afoul of the rule that says that any list op +erator followed by parentheses turns into a function, with all the list operators arguments found inside the parentheses. See perlop/Terms and List Operators (Leftward). ...
In reply to Re: Re: Re: Confused about unary +
by sgifford
in thread Confused about unary +
by Not_a_Number
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |