SPUG: Diff keys(%hast0) with keys(%hash1) both ways ?
DeRykus, Charles E
charles.e.derykus at boeing.com
Fri Apr 14 15:23:10 PDT 2006
Not as elegant but there's symmetry :)
... and warning-free execution.
use List::MoreUtils qw/uniq/;
foreach my $check ( uniq sort(keys %cleantests, keys %dirtytests) ) {
my $clean = exists $cleantests{$check} ? $cleantests{$check} : 0;
my $dirty = exists $dirtytests{$check} ? $dirtytests{$check} : 0;
print "$check: clean=$clean dirty=$dirty\n";
}
--
Charles DeRykus
-----Original Message-----
From: Atom Powers [mailto:atom.powers at gmail.com]
Sent: Friday, April 14, 2006 12:10 PM
To: SPUG Members
Subject: SPUG: Diff keys(%hast0) with keys(%hash1) both ways ?
I some values/checks that could be "clean", "dirty", or both and I want
to find out how often it is clean and/or dirty.
$cleantests{$check} holds the number if times a check was clean,
similarly $dirtytests{$check} is how many times a check was dirty.
Again, a check could be "clean" 5 times a "dirty" 16 times, or whatever.
I'm having problems finding the checks which are "clean" but not
"dirty".
I have:
--
foreach my $check ( keys %dirtytests ) {
if ($cleantests{$check}) {
print DATA $check . ":" . $dirtytests{$check} . "_" .
$cleantests{$check} . "\n";
} else {
print DATA $check . ":" . $dirtytests{$check} . "_0\n";
}
}
--
But I also want to be able to do this for the $cleantests{$checks} which
are not dirty.
--
print DATA $check . ":0_" . $cleantests{$check} . "\n";
--
I could
--
my @clean = keys(%cleantests);
--
and somehow undef a check from the array when I am doing
keys(%dirtytests), but I don't know if you can remove a value from an
array without knowing it's index.
I can't undef($cleantests{$check}) because I need to use those value
later.
--
--
Perfection is just a word I use occasionally with mustard.
--Atom Powers--
_____________________________________________________________
Seattle Perl Users Group Mailing List
POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays
WEB PAGE: http://seattleperl.org/
More information about the spug-list
mailing list