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)


In reply to Re: Real World 1, Great Expectations 0 by wog
in thread Real World 1, Great Expectations 0 by hsmyers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.