People familiar with IO::Handle, please skip the following paragraph.

For the uninitiated, there's an OO interface to the filehandles in Perl. All you do is use IO::Handle and at the expense of a mere *cough* few thousand lines of Perl code, you can replace non-OO access to filehandles:

open(my $foo,'<+ /dev/null'); #old select($foo); $|=1; select(STDOUT); print $foo "|<3wl! 31337 d00d!"; printf $foo "%.02f", $money; $fd = fileno $foo; read($foo, $input, 1024) unless eof $foo; @stats = stat $foo; close $foo; #new $foo->autoflush(1); $foo->print("|<3w1! 0bj3ct 0r13nt3d f1l3h4ndl3z! l33t!"); $foo->printf("%.02f", $money); $fd = $foo->fileno; $foo->read($input, 1024) unless $foo->eof; @stats = $foo->stat; $foo->close;
OK, lesson over.

Everybody back with me? Good.

Now, some people may be familiar with this nifty oneliner, that demonstrates the nature of the magic by which Perl associates filehandles with the IO::Handle package:

$ perl -le 'STDIN->close()' Can't locate object method "close" via package "IO::Handle" at -e line + 1.
This shows that Perl is magically understanding that STDIN is a filehandle being used as an object, and trying to invoke IO::Handle::close, and failing (because IO::Handle wasn't required).

I've known about this problem, but something occurred to me today that reveals a serious issue with this magic. Please read on, I'd like to know if anyone agrees with me.

Now, the only way for Perl to go looking for IO::Handle is for it to treat the 'STDIN' as a symbolic reference. Ignoring the fact that in no other case does the $obj in $obj->foo() attempt to treat $obj as a symbolic reference, but Perl is treating 'STDIN' as a symbolic reference in violation of strict refs (that's the -Mstrict) without so much as a warning.

Comments?

--Stevie-O
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc

In reply to Bad news for IO::Handle magic by Stevie-O

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.