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

Re: Fun with open() on a string

Thread Previous | Thread Next
From:
Graham Barr
Date:
July 30, 2008 06:31
Subject:
Re: Fun with open() on a string
Message ID:
9E0196E5-15D6-481E-BD9A-3CD4760EF3A5@pobox.com

On Jul 30, 2008, at 8:21 AM, H.Merijn Brand wrote:

> On Wed, 30 Jul 2008 08:08:38 -0500, Graham Barr <gbarr@pobox.com>  
> wrote:
>
>>
>> On Jul 29, 2008, at 8:42 AM, Mark Mielke wrote:
>>
>>> Peter Scott wrote:
>>>> This very nearly qualifies as an easter egg.  Inspect the  
>>>> following:
>>>>
>>>>   perl -e 'close STDIN; open STDIN, "<", \$x; print <>'
>>>>
>>>> Guess what it does.  Run it.  See if you were right.
>>>>
>>>> Bugworthy?  I don't know; maybe, that's why I mention it here.  But
>>>> it had
>>>> some entertainment value for me today.
>>>>
>>>
>>> +1 for weird. :-)
>>>
>>> Do you have an explanation for why it does what it does? :-)
>>
>> Yes. <> is reading from stdin in C (file descriptor 2) which will be
>
> No, File descriptor 0. 1 is stdout, 2 is stderr

Yes you are right. That goes to prove you should not send mail just as  
you wake up

:-)

Graham.


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