>>>>> "Bob" == Bob <[EMAIL PROTECTED]> writes:
Bob> Here's one for "in one list not another", like to find
Bob> obsolete mailboxes or new users, given new and
Bob> old lists. I have lists of rcptusers(ldap), dspam users,
Bob> and mailboxes. To not blindly feel out thousands of
Bob> everything just to add or delete one.
Bob> (Ignore hpot addresses fed to harvest bots at end).
Bob> -Bob Dodds
Bob> _______________________________________________________
Bob> #!/usr/bin/perl -w
Bob> #-w
Bob> use strict;
Bob> use Benchmark;
Bob> sub in_a_not_b {
Bob> my ( $ra , $rb , %u , %v ) = ( $_[0] , $_[1] , () , () ) ;
Bob> grep { $_ and ! ($u{$_}++) } @$rb ;
Bob> grep { $_ and ! ($v{$_}++) and ! $u{$_} } @$ra ;
Bob> }
Ugh. void greps which would be better stated as for-modifiers:
$_ and ! ($u{$_}++) for @$rb ;
$_ and ! ($v{$_}++) and ! $u{$_} for @$ra;
But even then, I'd just do this:
sub in_a_not_b {
my %notes;
$notes .= "a" for @{$_[0]};
$notes .= "b" for @{$_[1]};
grep { $notes{$_} eq "a" } for sort keys %notes;
}
Mostly because the code then fits the description, *and* it does the job
pretty efficiently.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!