Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: PerlIO: crlf layer on Windows interfering with UCS-2 unicode

by ikegami (Pope)
on Jun 03, 2008 at 10:53 UTC ( #689841=note: print w/ replies, xml ) Need Help??


in reply to PerlIO: crlf layer on Windows interfering with UCS-2 unicode

Surprisingly, the trick only works for open, not binmode.

use strict; use warnings; sub dump_layers(*) { my @layers = PerlIO::get_layers($_[0]); print STDERR "@layers\n"; } my $file = 'temp'; { open(my $fh, '>:raw:encoding(ucs-2le):crlf:utf8', $file) or die; dump_layers($fh); } { open(my $fh, '<:raw:encoding(ucs-2le):crlf:utf8', $file) or die; dump_layers($fh); } unlink $file; binmode STDOUT, ':raw:encoding(ucs-2le):crlf:utf8' or die; dump_layers STDOUT; binmode STDIN, ':raw:encoding(ucs-2le):crlf:utf8' or die; dump_layers STDIN;
unix encoding(UCS-2LE) utf8 crlf utf8 unix encoding(UCS-2LE) utf8 crlf utf8 unix crlf encoding(UCS-2LE) utf8 unix crlf encoding(UCS-2LE) utf8

The only solution I've found follows, but I don't like it.

binmode $fh, ':raw:pop:encoding(ucs-2le):crlf:utf8'; # ^^^

The issue is that :raw disables the existing :crlf layer (but doesn't remove it) when using binmode. Then, the later :crlf reactivates the earlier :crlf layer instead of adding a new layer, messing everything up.


Comment on Re: PerlIO: crlf layer on Windows interfering with UCS-2 unicode
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://689841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-25 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls