in reply to Re: Text::CSV - parsing
in thread Text::CSV - parsing
Good post, just a note: this will not work right if the quoted strings happen to be broken onto two lines. In that case, Text::CSV's getline is better (see the section "Embedded newlines" in the doc):
use warnings; use strict; use Text::CSV; use Data::Dump; my $csv = Text::CSV->new ({ binary=>1, auto_diag=>2, quote_char=>"'", allow_whitespace=>1 }); while ( my $row = $csv->getline( \*DATA ) ) { dd $row; } $csv->eof; __DATA__ (101, '1997-02-25', 'S1', 31.00, NULL, 0.00, 'this becomes two fields, so no go', 5.11), (102, '1998-03-26', 'S1', 31.00, NULL, 0.00, 'this will remain one field', 6.11),
Output:
[ "(101", "1997-02-25", "S1", "31.00", "NULL", "0.00", "this becomes two fields,\nso no go", "5.11)", "", ] [ "(102", "1998-03-26", "S1", "31.00", "NULL", "0.00", "this\nwill remain one field", "6.11)", "", ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Text::CSV - parsing
by Eily (Monsignor) on Mar 14, 2017 at 18:24 UTC |