Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by chromatic (Archbishop)
on Mar 20, 2000 at 23:18 UTC ( #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? - Answer 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2017-11-18 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?