Split a string on unquoted separators
parse_line()
Section titled “parse_line()”Using parse_line() of Text::ParseWords:
use 5.010;use Text::ParseWords;
my $line = q{"a quoted, comma", word1, word2};my @parsed = parse_line(',', 1, $line);say for @parsed;Output:
"a quoted, comma" word1 word2Text::CSV or Text::CSV_XS
Section titled “Text::CSV or Text::CSV_XS”use Text::CSV; # Can use Text::CSV which will switch to _XS if installed$sep_char = ",";my $csv = Text::CSV->new({sep_char => $sep_char});my $line = q{"a quoted, comma", word1, word2};$csv->parse($line);my @fields = $csv->fields();print join("\n", @fields)."\n";Output:
a quoted, comma word1 word2my $csv = Text::CSV_XS->new({sep_char => $sep_char, allow_whitespace=>1});Output:
a quoted, commaword1word2Documentatoin: http://search.cpan.org/perldoc/Text::CSV