Subject: | BOM-signed CSVs: strange behavior |
Date: | Fri, 07 Aug 2009 16:04:39 +0400 |
To: | bug-Text-CSV_XS [...] rt.cpan.org |
From: | Anton Soldatov <pinnsvin [...] mail.ru> |
Hello,
I actually don't know whether it's a bug or not, but anyway...
uname -a: Linux sparta 2.6.25-14.fc9.i686 #1 SMP Thu May 1 06:28:41 EDT 2008 i686 athlon i386 GNU/Linux
perl -v: This is perl, v5.10.0 built for i386-linux-thread-multi
module: Text::CSV_XS 0.65 (but also actual for Text::CSV_PP as far as I can test)
Problem: when I try to open a Unicode CSV file signed with the BOM in binary mode, $csv->getline returns nothing.
Currecnt fix: currently I'm using open_bom from File::BOM instead of the built-in open.
Test script to reproduce the bug:
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::CSV_XS;
use File::BOM qw(open_bom);
my $enco = 'UTF-16LE';
my $file = 'bom.csv';
my $use_bom = 0; # set to 1 to use open_bom
my $csv = Text::CSV_XS->new({ binary => 1, sep_char => "\t", eol => "\r\n" });
my $io;
if ($use_bom) {
open_bom $io, $file, ":encoding($enco)";
} else {
open $io, "<:encoding($enco)", $file;
}
while (my $row = $csv->getline($io)) {
print "$row\n";
}
close $io;
exit 0;
Output on my machine:
$use_bom = 0 - nothing
$use_bom = 1 - two rows read, just as planned:)
ARRAY(0x976a114)
ARRAY(0x9774df4)
Test csv: please see the attachment (CSV in UTF-16LE)
Best regards,
Anton Soldatov
Message body not shown because it is not plain text.