J
jeffg
I'm trying to use CSV_XS to parse log files.
Each field is separated by a comma and surround by double quotes.
Within each field, there may be embdedded double and single quotes.
These embedded quotes are escaped by a backslash.
I'm having trouble getting it to work. I have two questions:
1) The entire script fails at the first line it can't parse. How can
I make it ignore the current line and continue?
I'm using getline() to read the file, like this:
open my $io, "<", $logname or warn("Cannot open file ${logname} for
reading. $!");
while (my $line = $csv->getline($io)) {
}
2) How should I instantiate my $csv object to get it to recognize my
escape character?
I tried this:
my $csv = Text::CSV_XS->new( {
escape_char => '\\',
sep_char => ',',
binary => 1,
} );
Each field is separated by a comma and surround by double quotes.
Within each field, there may be embdedded double and single quotes.
These embedded quotes are escaped by a backslash.
I'm having trouble getting it to work. I have two questions:
1) The entire script fails at the first line it can't parse. How can
I make it ignore the current line and continue?
I'm using getline() to read the file, like this:
open my $io, "<", $logname or warn("Cannot open file ${logname} for
reading. $!");
while (my $line = $csv->getline($io)) {
}
2) How should I instantiate my $csv object to get it to recognize my
escape character?
I tried this:
my $csv = Text::CSV_XS->new( {
escape_char => '\\',
sep_char => ',',
binary => 1,
} );