Not trying to do anything "useful" here, just experimenting with Perl a bit. I read in Intermediate Perl (p. 146) that the print function (as well as many of the built-in operations on filehandles) are actually just using Perl's indirect object notation to call the print method on the filehandle object.

So, I was curious to see whether this worked with the standard filehandles; STDOUT in particular. However:

my $ofh = *STDOUT; $ofh->print("test 1\n");

didn't work. Nor did:

my $ofh = \*STDOUT; $ofh->print("test 2\n");

or even (not that I expected this to):

STDOUT->print("test 3\n");

So, what gives? I checked perlfaq5, IO::Handle, and perldata but didn't see anything that answered my question specifically. Is there something I'm doing wrong or are the STD* filehandles "special" in some way?

Update: Thanks, all!


In reply to Regarding STDOUT and indirect object notation for print by romandas

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.