Subject: | Inconsistent behaviour from header() method with carriage return EOL's |
We hit two issues when calling the header() method while parsing a CSV file that uses carriage returns for EOL:
1) *All* the data was lower cased, not just the header keys. If the data uses newline as the EOL character, only the header keys are lower cased, while the remaining rows maintain their case. Here's a code snippet to reproduce the issue.
use Text::CSV_XS;
use Data::Dumper;
my $data = "foo,BAR,baz\rONE,two,Three\rFour,FIVE,six\r";
open my $fh, "<", \$data;
my $csv = Text::CSV_XS->new({binary => 1});
$csv->header($fh);
while (my $rec = $csv->getline_hr($fh)) {
print Dumper $rec;
}
2) If you explicitly add the option eol => "\r" when creating the Text::CSV_XS object in the above example, there is *no* output (the file handle is at EOF before the while loop is executed?).
Using $csv->column_names($csv->getline($fh)); instead of header() was a sufficient workaround.