http://www.perlmonks.org?node_id=182908


in reply to Import CSV to Database

This code is from the Perl Cookbook. It returns an array.
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; } # Use like so: my ( $row1, $row2, $row3, ) = parse_csv($csv_line);