in reply to Re: Re: Comma separated list into a hash
in thread Comma separated list into a hash
how to handle commas that belong in the data value
If quotes are used to disambiguate, it's fairly easy to parse with a regex:
local $_ = q(one, two, "three, four", five, six); my @words = m( \s* # gobble any leading whitespace ( # capture either: "[^"]+" # a group of quoted letters | # or [^,]+ # a group of non-quoted letters, except commas ) (?:,|$) # anchor the match to a comma, or end of string )gx;
Of course, that suffers from other problems, such as going all wonky with unbalanced quotes. But it's a fairly simple way to parse well-formed data, and I thought it might be helpful for some to look at.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re4: Comma separated list into a hash
by dragonchild (Archbishop) on Apr 26, 2004 at 18:16 UTC | |
by revdiablo (Prior) on Apr 26, 2004 at 20:24 UTC |