Why?

In print $handle @args the $handle is syntactically distinct from an ordinary argument in there is no space between it and the following arguments.

This is forbidden in "normal" perl code, we call it "two terms in a row" (short TTIAR)

So if Perl allowed arbitrary expressions as file handles, it wouldn't catch TTIAR errors later, leading to extremely weird behavior. Consider

print $some + $var * 5 3; # ^ # forgot an operator

In this example, everything up to (and including) the 5 would be parsed as a file handle if Perl allowed arbitrarily complex expressions as file handles. No syntax error would be emitted.

So, there needs to be a complexity limit as to what is allowed as a file handle. The choice is "a single variable, bareword or { ... } block".


In reply to Re: FileHandle in a Hashref by moritz
in thread FileHandle in a Hashref by Anonymous Monk

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.