http://qs321.pair.com?node_id=126711


in reply to How can I extract the username and hostname/domain from e-mail addresses?

The Mail::Address and Mail::Header modules can do this task:

use Mail::Header; use Mail::Address; my $header = Mail::Header->new([@lines]); my($from) = Mail::Address->parse($header->get("From")); my($user,$host) = ($from->user(),$from->host());

Edit by tye

Replies are listed 'Best First'.
Re: Re: How can I extract the username/domain?
by wog (Curate) on Nov 21, 2001 at 06:44 UTC
    my $from = Mail::Address->parse($header->get("From"));
    should be
    my($from) = Mail::Address->parse($header->get("From"));
    (because Mail::Address->parse returns an array, and we don't want it's length.)