If you have any control over the format, you might consider changing it to match the CSV spec - something standard. Then Text::CSV will help you. The example below is only slightly modified from the examples in the POD
#!/usr/bin/perl -w use strict; use Text::CSV_XS; while( <DATA> ){ my $line = $_; my @input; my $csv = Text::CSV_XS->new({ # defaults are: ["]["][,][0] quote_char => '"', escape_char => '"', sep_char => ',', binary => 0 }); if( $csv->parse( $line ) ){ @input = $csv->fields; } else { my $err = $csv->error_input; warn "Text::CSV_XS->parse() failed in line $. on argument '" , $err, "'\n"; } foreach my $item (@input){ print "$item\n"; } print "\n"; } # first line parses 'correctly' - second does not. __DATA__ this,that,those,"these (not enough, nope, never)",there this, that, those, these (not enough, nope, never), there
In reply to Re: Splitting a comma-delimited string where a substring could countain commas
by mrbbking
in thread Splitting a comma-delimited string where a substring could contain commas
by Eisbar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |