in reply to Comparing two sets
#!/usr/bin/perl use strict; use warnings; my %hash = ("One","1","Two","2","Three","3","Four","4"); my @lines = ("One", "Two", "Three"); my %count; foreach my $element (@lines) { $count{$element}++; } foreach my $i (sort {$hash{$a} <=> $hash{$b}} keys %hash) { if (exists $count{$i}) { print "$i,$hash{$i},Hit\n"; } else { print "$i,$hash{$i},Miss\n"; } } __END__ One,1,Hit Two,2,Hit Three,3,Hit Four,4,Miss
Your output lines are also much more complex than they need to be; see Quote and Quote like Operators. As well, you don't need to stringify to use something as a hash key - Perl does that automatically. Compare your output lines to the ones I have above.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing two sets
by Gizmo (Novice) on May 20, 2010 at 14:15 UTC | |
by Old_Gray_Bear (Bishop) on May 20, 2010 at 18:46 UTC |