SPUG: Diff keys(%hast0) with keys(%hash1) both ways ?
Peter Darley
pdarley at kinesis-cem.com
Fri Apr 14 12:43:45 PDT 2006
Atom,
I think this is really a data structure issue. You could re-arrange so you
have a single hash instead of two hashes:
for $Check (keys %Tests)
{
if ($Tests{$Check}{Dirty})
{
if ($Tests{$Check}{Clean})
{
print "$Check : $Tests{$Check}{Dirty} dirty checks :
$Tests{$Check}{Clean} clean checks"
}
else
{
print "$Check : $Tests{$Check}{Dirty} dirty checks"
}
}
elsif ($Tests{$Check}{Clean})
{
print "$Check : $Tests{$Check}{Clean} clean checks"
}
else
{
print "$Check : $Tests{$Check}{Dirty} dirty checks :
$Tests{$Check}{Clean} clean checks"
}
}
Thanks,
Peter Darley
-----Original Message-----
From: spug-list-bounces+pdarley=kinesis-cem.com at pm.org
[mailto:spug-list-bounces+pdarley=kinesis-cem.com at pm.org]On Behalf Of
Atom Powers
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