I've had a quick google and can't find anything mentioned out there, so
I thought I'd ask the other hackers out there if they've had any
problems with Text::CSV_XS.

Let me explain; I've got a text file, where the fields are
TAB-separated, and there isn't any quoting (or more precisely quotes
aren't supposed to be special in any way).

So for example:

 one<tab>"two"<tab>three

Should give me three fields:
 one
 "two"
 three

The code I'm using to read and parse this is:

---- cut here ----
#!/usr/bin/perl -w
use strict;
use IO::File;
use Text::CSV_XS;
use Data::Dumper;

my ($csv, $io, $columns);

$csv = Text::CSV_XS->new({
        'binary'                => 1,
        'sep_char'              => "\t",
        'quote_char'    => undef,
});


$io = new IO::File "< testquote.csv";
if (not defined $io) {
        warn "can't open IO for testquote.csv: $!";
        return undef;
}

while ($columns = $csv->getline($io)) {
        # when there are no columns we've read the file
        # Text::CSV_XS is a bit pants when it reaches the end of the file
        last if not scalar @$columns;

        print Dumper($columns);

        $csv->combine(@$columns);
        print $csv->string, "\n";
}
---- cut here ----

and a representation of the file I'm testing with is:

---- cut here ----
one<tab>two<tab>three
one<tab>"two"<tab>three
"one"<tab>"two"<tab>"three"
fake line
my one<tab>two<tab>three
---- cut here ----

THe output I'm getting is a little worrying:

---- cut here ----
$VAR1 = [ 
          'one',
          'two',
          'three'
        ];
one     two     three
$VAR1 = [ 
          'one',
          'two  three'
        ];
one     two     three
$VAR1 = [ 
          'one  two     three
fake line'
        ];
one     two     three
fake line
$VAR1 = [ 
          'my one',
          'two',
          'three'
        ];
my one  two     three
---- cut here ----

All of these (with the exception of fake line) should have three fields.
As you can see this isn't the case. Has anyone else experienced this?

Is it a bug in Text::CSV, or have I inadvertently created a non-CSV that
looks a lot like one?

Once again, input and comments most appreciated,

Chisel
-- 
e:   [EMAIL PROTECTED]   | They asked how many employees we had,
w:   www.herlpacker.co.uk      | broken down by sex. Told them drugs
gpg: D167E7FE                  | and alcohol was more of a problem.

Reply via email to