Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Help!

by twerq (Deacon)
on Jul 29, 2002 at 13:31 UTC ( [id://185970]=note: print w/replies, xml ) Need Help??


in reply to Finding unique email addresses (was: Help!)

A quick-and-dirty fix could be to keep each "seen" email address as a key in a hash (which could get very large, but hey--).

This could get you going:
#!/usr/bin/perl
use Email::Find;

my %seen_emails;  # this could get big!
$file = shift;
open (FILE, $file) or die "Couldn't open filename: ";
while (<FILE>)
{
 $text = $_;

 my $finder = Email::Find->new(sub 
 {
     my($email, $orig_email) = @_;
     my $formatted_email = $email->format;
     if (!defined($seen_emails{$formatted_email})) {
          # remember we've seen this guy
          $seen_emails{$formatted_email} = 1;
          
          # and show this email addy
          print $formatted_email . "\n";
     }
     return $orig_email;
 });

 $finder->find(\$text);



(this code is untested)

--twerq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://185970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-06-14 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.