这是我们在聊天中提出的。它每次都处理整个列表并产生一个充满列表的数组引用,每天一个。可以提供想要的那一天,以及“在第 x 天之后不再使用此域”黑名单。
use strict;
use warnings;
use feature 'say';
use Data::Dumper;
my $only_index = 3; # Read from command line with $ARGV[0] or use Getopt::Long
my %blacklist = ( # Each key in this hash represents one index/day
'2' => [ 'a', 'b' ], # and has an arrayref of domains that have replied on
'3' => [ 'c' ], # that day. We look at all keys smaller than the current
); # index in each iteration and ignore all these domains
my @domains; # holds the domains we have already seen for each list
my @lists = ([]); # Holds all the lists
my %moved; # the addresses we moved to the back
my $i = 0;
my @addresses = <DATA>;
while (@addresses) {
my $address = shift @addresses;
chomp $address;
$address =~ m/@([a-zA-Z0-9\-.]*)\b/;
my $domain = $1;
# If the domain has answered, do not do it again (finally, your map ;-))
next if
grep { /$domain/ }
map { exists $blacklist{$_} ? @{ $blacklist{$_} } : () } (0..$i);
next if exists $moved{$address}; # THIS line was missing
$i++ if (@{ $lists[$i] } == 2
|| (exists $moved{$address} && @addresses < 1));
if (exists $domains[$i]->{$domain}) {
push @addresses, $address;
$moved{$address}++;
# say "pushing $address to moved"; # debug
} else {
$domains[$i]->{$domain}++;
# send the email
# say "added $address to $i"; # debug
push @{ $lists[$i] }, $address;
}
}
# print Dumper \@lists; # Show all lists
print Dumper $lists[$only_index]; # Only show the selected list
1;
__DATA__
1@a
2@a
3@a
1@b
2@b
1@c
2@c
3@c
1@d
2@d
3@d
4@d
1@e
1@f
1@g
1@h
4@a
5@a
4@c