On Oct 23, 2006, at 8:45 AM, Adriano Ferreira wrote:
On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote:
This all works fine, but in
the last step of the program I am trying to get the program to tell
me key's that are unique to only the first hash. No matter what I do
it always prints out all of the values in the first hash, not the
keys that are unique to only the first hash.
foreach $key_h (keys %hash) {
foreach $key_dbm (keys %dbmhash) {
unless ($key_h eq $key_dbm) {
print "$key_h\n";
}
}
}
Romeo,
You are not doing what you said. The loop above prints the keys of the
first hash which differs from every key of the second hash. That
explains why it seemingly prints out all of the values.
foreach $key_h (keys %hash) {
print "$key_h\n" unless exists $dbmhash{$key_h};
}
will work better.
Thank you Adriano, that works nicely after I added:
use Memoize::AnyDBM_File;
before that I was getting this error:
AnyDBM_File doesn't define an EXISTS method at ....
I did a bit of googling and found that solution.
But I do have a question about your solution.
foreach $key_h (keys %hash) {
print "$key_h\n" unless exists $dbmhash{$key_h};
}
I don't understand why $dbmhash{$key_h} refers to the key whereas
earlier in the code when I do:
if ($hash{$key_h} <= 788) {
$dbmhash{"$key_h"} = $hash{$key_h};
}
$hash{$key_h} <= 788 is looking at the key value?
Thanks,
Romeo
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>