Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Email Purge

3 views
Skip to first unread message

Perl

unread,
Feb 22, 2009, 9:08:55 PM2/22/09
to scr...@perl.org
Cheers and thanks in advance for you help. I have a routine intended
to purge duplicate emails from a list. The code below is not working.
I remember seeing something like... foreach $email(@emails, @emails2))
{ etc ... but I'm lost. Any help is appreciated.
sub purge
{
open (LIST, "$list") or error("$list purge 1 email ");
while (my $line = <LIST>)
{
@emails = split(/\r?\n|\r/, $line);
@emails2 = @emails;
}
close (LIST);
foreach $email(@emails)
{

foreach $email2(@emails2)
{
if($email ne $email2)
{
$newemail .="$email\n";
}
else{$purgecnt++; }
}
}
open (LIST, ">>$list") or error("$list purge 2");
flock(LIST, LOCK_EX);
print LIST $newemail;
close (LIST);
&success("$list has been purged of $purgecnt duplicates");
}

Denis Poznyakov

unread,
Feb 26, 2009, 9:29:16 AM2/26/09
to perl, scr...@perl.org

#!/usr/bin/perl

use strict;

my $list = "e.txt";

purge();

sub purge {
open LIST, $list or die $!;
flock LIST, 2;
my @eml = <LIST>;
close LIST;

my %eml0 = map { $_ => 1 } grep { s/[\r\n]//g } @eml;

open LIST, ">l.txt" or die $!;
flock LIST, 2;
print LIST join("\n", sort keys %eml0);
close LIST;

0 new messages