develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #117355] [lu]cfirst don't respect 'use bytes'

Thread Previous | Thread Next
Victor Efimov via RT
August 12, 2013 20:53
[perl #117355] [lu]cfirst don't respect 'use bytes'
Message ID:
On Sun Aug 11 19:56:53 2013, rjbs wrote:

And another edge case when perl unicode not working well, is filenames.

Code below prints that two strings are same. Tries to open file with
name defined by one string, and then to reopen file with name defined by
second string. Second attempt fail.

So that is another case when user might want to use bytes::xxx, 
_is_utf8() etc to access perl string internals, because internals
matters in this case.

(btw, I have a program which have to deal with non-UTF filesystems, this
makes things even worse. it has to pass _binary_ strings representing
filename across whole program and I should be very careful and never
merge it with ASCII strings with utf-8 bin or Unicode strings)


use Encode;
use utf8;
use strict;
use warnings;

my $u = "\x{442}\x{435}\x{441}\x{442}"; # same as "ั‚ะตัั‚"

# plain binary data, for example part of binary file (say, JPEG)
my $bin = "\xf1\xf2\xf3";

my $ascii = "x";
my ($ascii_u, undef) = split(/ /, "$ascii $u");
die unless utf8::is_utf8($ascii_u);

print "original bin length:\t";
print length($bin) . "\t" . bytes::length($bin) ."\n";

my $bin_a = $bin.$ascii;

print "bin_a length:\t";
print length($bin_a) . "\t" . bytes::length($bin_a) ."\n";

my $bin_u = $bin.$ascii_u; # THIS LINE CONTAINS A BUG

die unless $bin_u eq $bin_a;
print "bin_u and bin_a are same!\n";

open my $f, ">", "$bin_u.tmp";
binmode $f;
syswrite $f, "TEST";
close $f;

open $f, "<", "$bin_a.tmp" or die "file not found $!";
original bin length:    3       3
bin_a length:   4       4
bin_u and bin_a are same!
file not found No such file or directory at line 39.

via perlbug:  queue: perl5 status: open

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About