Gizmo has asked for the wisdom of the Perl Monks concerning the following question:
so instead of getting:
Four,4,Miss Four,4,Miss Four,4,Miss Three,3,Miss Three,3,Miss Three,3,Hit Two,2,Miss Two,2,Hit Two,2,Miss One,1,Hit One,1,Miss One,1,Miss
I would like:
--------One,1,Hit Two,2,Hit Three,3,Hit Four,4,Miss
use strict; use warnings; my %hash = ("One","1","Two","2","Three","3","Four","4"); my @lines = ("One", "Two", "Three"); foreach my $i (keys %hash) { foreach my $n (@lines) { if ($i eq $n) { print "$i,", $hash{"$i"}, ",Hit\n"; } else { print "$i,", $hash{"$i"}, ",Miss\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing two sets
by kennethk (Abbot) on May 20, 2010 at 13:53 UTC | |
by Gizmo (Novice) on May 20, 2010 at 14:15 UTC | |
by Old_Gray_Bear (Bishop) on May 20, 2010 at 18:46 UTC | |
|
Re: Comparing two sets
by JavaFan (Canon) on May 20, 2010 at 13:44 UTC |