Hi, I'm playing with hashes trying to get myself more familiar with
them. I have a little program below that has a hash with some keys
and values in it. The program then copies some of the values/keys to
another hash depending on their values. 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.
Thank you for any help.
Romeo
#!/usr/bin/perl
use strict;
use warnings;
my %hash;
my %dbmhash;
my $key_h;
my $key_dbm;
my %onlyinfirsthash;
my $key_f;
dbmopen(%dbmhash, "dbmfilename", 0644)
or die "cannot open DBM";
%hash = (
picard => '789',
lego => '788',
joe3 => '787',
simone => '788',
joe => '800',
catdog => '9000',
moneydog => '8090',
);
foreach $key_h (keys %hash) {
print "$key_h from standard hash has a value of
$hash{$key_h}\n";
if ($hash{$key_h} <= 788) {
$dbmhash{"$key_h"} = $hash{$key_h};
#print "$key has a value of $hash{$key}\n";
}
}
print "\n\n";
foreach $key_dbm (keys %dbmhash) {
print "$key_dbm from dbmhash has a value of $dbmhash{$key_dbm}\n";
}
print "\n\n";
foreach $key_h (keys %hash) {
foreach $key_dbm (keys %dbmhash) {
unless ($key_h eq $key_dbm) {
print "$key_h\n";
}
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>