develooper Front page | perl.perl5.porters | Postings from December 2005

[perl #35180] inconsistency between PerlIO::get_layers and open/binmode

From:
Nick Ing-Simmons via RT
Date:
December 31, 2005 10:23
Subject:
[perl #35180] inconsistency between PerlIO::get_layers and open/binmode
> > > 
> > > open F, "foo.pl";
> > > 
> > > 
> > > # now try to open a temp file with same layers as F
> > > my $tmp = undef;
> > > my $F_layers = join "", map {":$_"} PerlIO::get_layers(F); 
> > > open $tmp, "+>$F_layers", undef;
> > > 
> > > my $tmp_layers = join "", map {":$_"} PerlIO::get_layers($tmp); 
> > > 
> > > print "MISMATCH !! $F_layers / $tmp_layers\n" unless $F_layers eq
> > > $tmp_layers;
> > > 
> > > # on Win32 : MISMATCH !! :unix:crlf / :unix:crlf:unix
> > 
> > I'm not sure that's really a bug, since open pushes some layers by
> > defaults depending on the platform. That's more a minor annoyance.
> 
> ":unix:crlf" seem to be the default layers on this platform.
> When $tmp is opened
> 
>     open $tmp, "+>$F_layers", undef;
> 
> ":unix:crlf" ($F_layers) are pushed on top of the default layers
> resulting in ":unix:crlf:unix:crlf" for $tmp. However ":crlf" is
> documented to be pushed only once
> 
>     :crlf
>     A layer that implements DOS/Windows like CRLF line endings.
>     ... ...
>     Note that this layer likes to be one of its kind: it silently
>     ignores attempts to be pushed into the layer stack more than once.
>     ... ...
> 
> and the result is ":unix:crlf:unix" (the rightmost ":crlf" is silently
> ignored). 
> 
> IMHO your code behaves exactly as documented.
> 
But the odd thing is if undef is replaced by a file name it works 
as original poster expected. 
So it seems the magic undef for temp file code is getting extra 
set of layers.




Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About