in reply to Regex Conundrum

It looks to me like you're trying to parse Text from Comma Separated Values. Hmm...I wonder if anyone's ever done this before?? Hmm... CPAN might be a good place to start looking... Wha? What's this? ...Text::CSV! Eureka, you're not the first person to have such a need! (I'm teasing, of course).

Here's an example straight from the Text::CSV POD:

use Text::CSV; $csv = Text::CSV->new(); # create a new object $status = $csv->parse($line); # parse a CSV string into fields @columns = $csv->fields(); # get the parsed fields

Don't use a regex to do what can be done more reliably with a tried and proven module. Text::CSV is the right tool for the job. You'll find it even properly handles commas embeded in quoted strings.


Dave

Replies are listed 'Best First'.
Re^2: Regex Conundrum
by dragonchild (Archbishop) on Jun 13, 2004 at 05:10 UTC
    Better is Text::xSV. In addition to allowing any character as the separator (instead of hard-coding comma), it actually takes into account embedded newlines, which Text::CSV doesn't do. Plus, it's a pure-perl solution that's almost as fast as Text::CSV_XS. And, tilly wrote it. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Great advice. ...a new favorite module. :)


      Dave