develooper Front page | perl.perl5.porters | Postings from September 2004

Re: [perl #31455] Dup DATA filehandle, lose initial data

Thread Previous | Thread Next
From:
Jim Carter
Date:
September 8, 2004 18:28
Subject:
Re: [perl #31455] Dup DATA filehandle, lose initial data
Message ID:
Pine.LNX.4.58.0409081541170.18295@simba.math.ucla.edu
On Mon, 6 Sep 2004, Nick Ing-Simmons via RT wrote:
> Can you try this with 
> PERLIO=perlio perl ...
> and 
> PERLIO=stdio perl ...

Yes, it fails equally with perlio and stdio.  

Do I _need_ to do a dup?  My original motivation was to use standard
features to encompass this unusual case: normally the table is a plain file
named on the command line, but for ultra paranoia I concatenate the script
and the table, and then specify '<&DATA'.  As a workaround, what I'm doing
now is to test for the string '<&DATA', and in that case return \*DATA
rather than opening the so-called filename.

I kind of figured that when a stream was duped, the remainder of the
original filehandle's buffer would be pre-stuffed into the new stream
object, so the duplication would be exact.  But of course that takes work,
and the cross-platform issues are probably a disaster.  If a partially used
stream object were copied either by memcpy or by its copy constructor, I
wonder if the result would be useable on most platforms?

Your point is well taken that both instances share the same file pointer, 
so if you do buffered I/O from both instances interleaved, the data would 
be totally trashed.  

James F. Carter          Voice 310 825 2897    FAX 310 206 6673
UCLA-Mathnet;  6115 MSA; 405 Hilgard Ave.; Los Angeles, CA, USA  90095-1555
Email: jimc@math.ucla.edu    http://www.math.ucla.edu/~jimc (q.v. for PGP key)

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