in reply to Problems With Parsing CSV File
Hopefully this will help you on your trouble shooting, but I get the correct result (e.g. The first set (1 & 6)of double quotes signify a text field that allows embedded commas and the second (2 & 5)and third sets (3 & 4) of double quotes signify an embedded double quote inside a double quoted string)
This is Perl 5.6.1 and Text::CSV_XS V 0.23
#!/usr/bin/perl -w use Text::CSV_XS; my $csv = Text::CSV_XS->new; my $column = ''; my $sample_input_string = '12345,Jim,,"""Smith, Jr.""",1234 W. Baker C +t., ,Ontario,CA,12345,123456789, ,,27-Apr-02,1234567 '; if ($csv->parse($sample_input_string)) { my @field = $csv->fields; my $count = 0; for $column (@field) { print ++$count, " => ", $column, "\n"; } print "\n"; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; }
Produces
1 => 12345 2 => Jim 3 => 4 => "Smith, Jr." 5 => 1234 W. Baker Ct. 6 => 7 => Ontario 8 => CA 9 => 12345 10 => 123456789 11 => 12 => 13 => 27-Apr-02 14 => 1234567
| XP matters not. Look at me. Judge me by my XP, do you? |
|
|---|