in reply to compare values within hash
use strict; use warnings; my %hash = ( key1 => [qw(a b c d e f)], key2 => [qw(a c d e f)] ); my @a1 = @{$hash{key1}}; my @a2 = @{$hash{key2}}; for my $i (0 .. $#a1) { unless (exists $a2[$i]) { print "No match for $a1[$i]\n"; next; } if ($a1[$i] eq $a2[$i]) { print "equal: $a1[$i], $a2[$i]\n"; } else { print "not equal: $a1[$i], $a2[$i]\n"; } } __END__ equal: a, a not equal: b, c not equal: c, d not equal: d, e not equal: e, f No match for f
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: compare values within hash
by ikegami (Patriarch) on Nov 23, 2008 at 16:53 UTC | |
by toolic (Bishop) on Nov 23, 2008 at 18:07 UTC | |
by ikegami (Patriarch) on Nov 23, 2008 at 18:55 UTC | |
|
Re^2: compare values within hash
by Anonymous Monk on Nov 23, 2008 at 15:19 UTC | |
by almut (Canon) on Nov 23, 2008 at 15:38 UTC |