http://qs1969.pair.com?node_id=11137297


in reply to Splitting in while loop

The usual "don't use a regex when a real parser exists" applies here too. Single quotes are technically a valid character in email addresses, as are commas and spaces when quoted. The following uses Email::Address to correctly parse and split such (admittedly very unusual and not recommended) addresses.

use warnings; use strict; use Email::Address; while (<DATA>) { for my $addr (Email::Address->parse($_)) { print $addr->address, "\n"; } } __DATA__ 'me'@here.com, "West, Casey" <casey@localhost> "those,foo"@there.com others@there.com you@there.com,them@there.com "Hello, World"@example.com

Outputs:

'me'@here.com casey@localhost "those,foo"@there.com others@there.com you@there.com them@there.com "Hello, World"@example.com