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

gibsonca has asked for the wisdom of the Perl Monks concerning the following question:

I have a fixed, text comma delimited set of lines that sometimes has commas in comments in some of the fields, how do I ignore those? For example:

a,b,"hey, you","str1, str2, str3",end

So this should be split into 5 fields. But

@fields = split(/\,/, $line);

does not take into account the quoted strings. What I want fields to be set to:

a b "hey, you" "str1, str2, str3" end

Maybe I am missing the obvious, but I am stuck on this. Any help appreciated.