open(local *BLACKLIST, "; @address =
; my $sep = "|"; my $keyLength = 6; my @blackListed = intersection(\@blacklist, \@address); print "Found: " . scalar(@blackListed) . "\n"; sub intersection { my ( $list1, $list2 ) = @_; my %strings; my $loop; # turn the biggest list into a strings hash. # AND loop through the smallest list. if ( $#{$list1} > $#{list2} ) { %strings = makeStringsHash( \$list1 ); $loop = \$list2; } else { %strings = makeStringsHash( \$list2 ); $loop = \$list1; } # run through the smallest of lists my @intersection = (); # for each key remember the last position ( the strings in the hash # are sorted, remember? ) my %lastPos = (); foreach my $entry ( @{ $$loop } ) { my $key = substr($entry, 0, $keyLength); my $pos = $lastPos{$key} || 0; my $tmp = index( $strings{$key}, $sep.$entry.$sep, $pos ); # if we found it in the big-list, add it to the intersection if ( $tmp != -1 ) { push @intersection, $entry; $lastPos{$key} = $tmp; } } return @intersection } sub makeStringsHash { my ( $list ) = @_; my %strings = (); $strings{substr($_, 0, $keyLength)} .= $sep . $_ . $sep foreach ( sort @$$list ); return %strings; }