[ale] Code/logic collection question

Fletch fletch at phydeaux.org
Mon Apr 23 21:23:01 EDT 2001

>>>>> "greg" == greg  <greg at turnstep.com> writes:

    greg> Quick and dirty: you'll probably want to manually pick out
    greg> some addresses, but it works:

    greg> perl -ne 'print "$1\n" if /(\w+@\w+\.\w+)/' pinefile | sort -u

        That would only pickup the first address on the line.  It's
also only going to pick up two level domains, e.g. foo.com but not
mail.foo.com, since \w+\.\w+ is actually going to give you mail.foo in 
that case.  It also would miss things like foo-bar.com (since - isn't
in the \w class).

perl -lne 'print $1 while /(\w+\@\S+\.\w+)/g' foo | sort -u

        Or if you want to eliminate the extra sort process:

perl -lne '$a{$1}++while/(\w+\@\S+\.\w+)/g;END{print for sort keys%a}' foo

        Of course the problem with this is that it'll tend to pickup
Message-Id's as well as addresses.  The best thing would probably be
to install the MailTools modules and use that to only pull out the
relevant interesting headers (To, From, Sender, Reply-To, et al).
MailTools is available from your friendly neighborhood CPAN mirror.
Run `perldoc Mail::Internet' and `perldoc Mail::Header' after
installing for more information.

cpan> m Mail::Header 
Module id = Mail::Header
    DESCRIPTION  Manipulate mail RFC822 compliant headers
    CPAN_USERID  GBARR (Graham Barr <gbarr at pobox.com>)
    CPAN_FILE    G/GB/GBARR/MailTools-1.15.tar.gz
    DSLI_STATUS  RdpO (released,developer,perl,object-oriented)
    MANPAGE      Mail::Header - manipulate mail RFC822 compliant headers
    INST_FILE    /usr/lib/perl5/site_perl/5.6.1/Mail/Header.pm

Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
770 933-0600 x211(w)  |  scary questions." -- Jules                =(___)=
                      |                                               U
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.

More information about the Ale mailing list