The Perl Cookbook has a recipe for parsing comma-separated data. This recipe (1.15) is taken from Mastering Regular Expressions. (My apologies if posting this is inappropriate).
BEGIN QUOTED MATERIAL:
Use the procedure in Mastering Regular Expressions.
Or use the standard Text::ParseWords module.sub parse_csv { my $text = shift; # record containing comma-separated values my @new = (); push(@new, $+) while $text =~ m{ # the first part groups the phrase inside the quotes. # see explanation of this pattern in MRE "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx; push(@new, undef) if substr($text, -1,1) eq ','; return @new; # list of values that were comma-separated }
END QUOTED MATERIALuse Text::ParseWords; sub parse_csv { return quotewords(",",0, $_[0]); }
The Perl Cookbook is a must-have book for any perl programmer. If you don't have a copy, please buy one. It has helped me immensely.
In reply to Re: Reading and writing CSV
by hangmanto
in thread Reading and writing CSV
by Concept99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |