develooper Front page | perl.perl5.porters | Postings from May 2010

Re: [perl #75106] binmode $fh, ":raw" doesn't undo :utf8 on win32

Thread Previous | Thread Next
From:
Eric Brine
Date:
May 15, 2010 21:29
Subject:
Re: [perl #75106] binmode $fh, ":raw" doesn't undo :utf8 on win32
Message ID:
AANLkTinQsmZx1DcEmWDeeGyRc_Yd2XHx1j6P7KAfyWpA@mail.gmail.com
A workaround that will work for you is to make a new handle from the fd.
(Creating a new handle from the handle suffers from the bug too.) As a
possible bonus, you don't affect the layers of the original handle.

#!perl
use strict;
use IO::File;
use POSIX qw(SEEK_SET);
use Test::More;

my $t = IO::File->new_tmpfile;
binmode $t, ":utf8";
print $t chr(3434);

$t->flush;
open my $t2, '<&=:perlio:raw', fileno($t) or die $!;
seek $t2, 0, SEEK_SET;

my $s = <$t2>;
is length $s, 3;
ok !utf8::is_utf8($s);

done_testing;

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