The obvious you're missing is that
print OUT;
is just relying on yet another perl Do-What-I-Mean feature. The bareword OUT happens to be a filehandle, and the statement resolves to a bare print statement (to that filehandle). A bare print results in printing $_.

In fact, a bareword after print is always interpreted as a filehandle1, no matter if it exists:

$ perl -wle 'print OUT' Name "main::OUT" used only once: possible typo at -e line 1. print() on unopened filehandle OUT at -e line 1.
With indirect filehandles that isn't the case: here the filehandle is a scalar holding a reference to a glob. Perl can't figure out what you mean (and imho ought not, anyways), so your variable's content gets printed. Only with print $expr LIST inspection of $expr is done.

<update>

$ perl -wle 'print $fh' Name "main::fh" used only once: possible typo at -e line 1. Use of uninitialized value in print at -e line 1. $ perl -wle 'print $fh $bar' Name "main::bar" used only once: possible typo at -e line 1. Name "main::fh" used only once: possible typo at -e line 1. Can't use an undefined value as a symbol reference at -e line 1.

Only in the latter case perl tries to resolve $fh to a filehandle.

1) unless your bareword is a constant as in

$ perl -wle 'use constant OUT => "foo";print OUT' foo
</update>

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Bareword vs. Indirect Filehandle behaviour by shmem
in thread Bareword vs. Indirect Filehandle behaviour by johngg

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.