develooper Front page | perl.perl5.porters | Postings from July 2008

Re: Fun with open() on a string

Thread Previous | Thread Next
From:
Mark Mielke
Date:
July 30, 2008 07:12
Subject:
Re: Fun with open() on a string
Message ID:
489076B1.8030102@mark.mielke.cc
Graham Barr wrote:
>> Peter Scott wrote:
>>> This very nearly qualifies as an easter egg.  Inspect the following:
>>>    perl -e 'close STDIN; open STDIN, "<", \$x; print <>'
>
> Yes. <> is reading from stdin in C (file descriptor 2) which will be 
> what was first opened after closing STDIN.
> The open STDIN, "<", \$x causes the PerlIO module to be loaded, so the 
> first file opened is PerlIO.pm
> What you see in the output is what is after the __END__ in PerlIO.pm

I would have been more impressed if it WAS an easter egg... Hahaha...

Thanks for the explanation, Graham.

Cheers,
mark

P.S. This sort of issue has bit me before. On some systems, init runs 
/etc/inittab entries without an STDIN, STDOUT, or STDERR. This leads to 
many issues as these file descriptors are inevitable assigned some 
important, and if the script assumes STDIN, STDOUT, or STDERR do exist, 
and do something with them, or close them...

-- 
Mark Mielke <mark@mielke.cc>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About