Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Answer: How can I split a comma-delimited string when the fields can have commas in them?

( #5735=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How can I split a comma-delimited string when the fields can have commas in them? contributed by chromatic

The best answer is to use Text::CSV from CPAN. Otherwise, you'll have to craft a regex which can handle obscure cases like commas between quotes, escaped quotes within quotes, and other funny stuff like that.

One possibility is:

$string =~ m!"*?([^,])"*?(?:=,)!;

Comment on Answer: How can I split a comma-delimited string when the fields can have commas in them?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-22 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (207 votes), past polls