Parse comma separated data
Import data in CSV format. Normally an easy task using split but sometimes, the fields will have comma's enclosed by quotes.
Something like.
Aaron, "123 Main St, USA", 555-555-1212
Assuming your string gets put into $text.
Taken from Jeffrey Friedl's Mastering Regular Expressions
Something like.
Aaron, "123 Main St, USA", 555-555-1212
Assuming your string gets put into $text.
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 ',';
Taken from Jeffrey Friedl's Mastering Regular Expressions