in reply to Parsing data that may or may not be CSV

Try a different split regexp. This one seems to work, though it may be just a step in the right direction:
while ( <DATA> ) { print join "\n", split /(?:\s+,?\s*|,\s*)/, $_; print "\n"; } __DATA__ foo@foo.com bar@bar.com, foo@foobar.com bar@foo.com , bar@foobar.com

Replies are listed 'Best First'.
Re: Re: Parsing data that may or may not be CSV
by BlueLines (Hermit) on Apr 19, 2002 at 18:19 UTC
    This doesn't work:
    while ( <DATA> ) { push @addrs, split /(?:\s+,?\s*|,\s*)/, $_; } print Dumper \@addrs; __DATA__ foo@foo.com bar@bar.com, foo@foobar.com bar@foo.com , bar@foobar.com
    produces the following output:
    $VAR1 = [ '', 'foo@foo.com', 'bar@bar.com', 'foo@foobar.com', 'bar@foo.com', 'bar@foobar.com' ];
    That empty entry at $addrs[0] is what I'm trying to avoid.

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.