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

Parsing email addresses with a regex is not easy, Mail::Address should help.

For splitting the list,

my @addresses = split /(?:\s|,)+/, $cgi->param('addresses');
The (?:..) construct is for grouping only, without setting $1. It's used to prevent split from inserting separators as extra array elements. A character class of whitespace and comma could be used instead.

After Compline,
Zaxo

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:28 UTC
    This doesn't work either:
    #!/usr/bin/perl use Data::Dumper; my $addresses = ' foo@foo.com bar@bar.com, foo@foobar.com bar@foo.com , bar@foobar.com '; my @addresses = split /(?:\s|,)+/, $addresses; print Dumper \@addresses;
    produces:
    $VAR1 = [ '', 'foo@foo.com', 'bar@bar.com', 'foo@foobar.com', 'bar@foo.com', 'bar@foobar.com' ];
    I agree that parsing email addresses via a regex is next to impossible, but fortunately for me I'm not required to verify the addresses :-)

    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.