http://qs321.pair.com?node_id=119595


in reply to Real World 1, Great Expectations 0

Your error message indicates that you had print $handles[$i] "Hi how the hell are ya!";, not what you copied here, so I am going to assume that is what you meant to copy. (And copying-and-pasting in the future will prevent transcription mistakes like this.)

Your problem is caused by an odd ambiguity of the "indirect object" syntax that print uses. That is, when you say:

something $array[$i]
would it mean
something {$array} [$i]
or
something {$array[$i]}
(where the {} can be used to set off the actual "object" you want to act on)? To resolve this ambiguity without incuring too much lookahead, perl treats it like:
something {$array} [$i]
You do have arguments after it, so concievably perl could disambiguite:
something $array[$i] $something_else
into:
something {$array[$i]} $something_else
but it doesn't try to look that far ahead, it just treats it like:
something {$array} [$i] $something_else
which is a syntax error because it has no comma (update: after the [$i])

Thus, there are two ways to make that take $handles[$i] be the first argument:

update: see also perlobj which discusses this ambiguity under the heading "WARNING".

(update: minor grammatical edit(s) above)