I don't think there is any bug, and in fact your code is very suspicious. It does not seem to me that you have utf8 flag turned on for your files. The mention of your attempt to open file with binmode, simply does not fit in the context at all. Why binmode has anything to do with what you are attempting?
Hope those little sample code help you understand how Perl handles unicode file IO. The first example works as expected:
use strict; use warnings; open(FILE, ">:utf8", "a.txt"); print FILE "a\x{2322}bcd\n"; close FILE; open(FILE, "<:utf8", "a.txt"); while (my $line = <FILE>) { print substr($line, 0, 3); } close FILE;
This second example does not work, and it should not work: (The only difference here is that files are opened without :utf8)
use strict; use warnings; open(FILE, ">", "a.txt"); print FILE "a\x{2322}bcd\n"; close FILE; open(FILE, "<", "a.txt"); while (my $line = <FILE>) { print substr($line, 0, 3); } close FILE;
In reply to Re: substr on utf8-strings
by pg
in thread substr on utf8-strings
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |