develooper Front page | perl.perl5.porters | Postings from April 2003

Re: [perl #22010] open(F, "<&DATA") fails silently (perlbug20030421: message 16 of 20)

Thread Previous
From:
Nick Ing-Simmons
Date:
April 30, 2003 05:34
Subject:
Re: [perl #22010] open(F, "<&DATA") fails silently (perlbug20030421: message 16 of 20)
Message ID:
20030430123401.2351.2@bactrian.elixent.com
Josh Purinton <perlbug20030421.5.jp@xoxy.net> writes:
>On Sun, Apr 27, 2003 at 07:52:29PM -0000, Nick Ing-Simmons wrote:
>> >Fair enough. Currently perldata.pod simply states:
>> >   The filehandle is left open pointing to the contents after __DATA__.
>> >
>> >It might help to add a warning like:
>> >   Unlike all other filehandles, DATA is read by perl while reading the
>> >   program.  
>> 
>> But it isn't really unlike other file handles.
>
>Interesting. What other file handles does the perl interpreter read from
>without the script explicitly requesting it? (And where is this behavior
>documented?)

It depends what you thought I meant. I was just saying that any file handle
which is buffered by stdio will have file position "wrong" when used 
as in Subject: line e.g. consider:

#!perl
open(FOO,__FILE__);
my $a = getc(FOO);
open(BAR,"<&FOO");
print "FOO=",tell(FOO)," BAR=",tell(BAR),"\n";
__END__

We have "read" one character (and my locale as such that that means 1 byte)
but that does NOT mean that the numeric fd's file posn is 1.
When I run that on my 5.8 (which defaults to :stdio)

perl /tmp/x
FOO=1 BAR=124
nick@bactrian 1003$

But :perlio "fixes" it:

nick@bactrian 1003$ PERLIO=perlio perl /tmp/x
FOO=1 BAR=1
nick@bactrian 1004$



-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/


Thread Previous


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