#!/usr/bin/perl # # variant from Cookbook # sub parse_csv { my $text = shift; my @new = (); push (@new, $+) while $text =~ m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx; push (@new, undef) if substr($text, -1, 1) eq ","; return @new; } # # second variant from Cookbook # (not interesting - nothing to optimize) ;-) # sub parse_csv2 { use Text::ParseWords; return quotewords(",",0,$_[0]); } # # my variant # sub parse_csv3 { local $_ = $_[0]; s/\"(.*?)(?; @fields = parse_csv3($line); for ($i = 0; $i < @fields; $i++) { print "$i : $fields[$i]\n"; }