in reply to Re: Managing multiple keys in a hash table...
in thread Managing multiple keys in a hash table...
If don't know if your solution does the right thing or not, but I do know it can be optimized. What follows does exactly the same thing as yours, except it does it in O(n) time instead of O(n*n)
my @list1 = qw/a b c d e f g/; my @list2 = qw/a b c d e /; my %one = ( a => 1, b => 1, c => 1 ); my %two = ( f => 1, g => 1 ); my %list1; undef @list1{@list1}; my %list2; undef @list2{@list2}; foreach my $key (keys %one) { if (exists $list1{$key} && exists $list2{$key}) { print "File 1 $key", $/; } } foreach my $key (keys %two) { unless (exists $list1{$key} && exists $list2{$key}) { if (exists $list1{$key} || exists $list2{$key}) { print "File 2 $key", $/; } } }
|
|---|