Hi there,
If I have a Hash of Arrays, how to you find out if a value exists for a given key.
So if I wanted to find out if '1' exists in key1, how do I do that?
I've tried, if exists, grep, defined, searched this forum, can't get it to work etc
If I have a Hash of Arrays, how to you find out if a value exists for a given key.
Code:
use Data::Dumper;
#populate hash
foreach (1 .. 4) {
push @{ $hash{key1} }, $_;
}
foreach (5 .. 9) {
push @{ $hash{key2} }, $_;
}
I've tried, if exists, grep, defined, searched this forum, can't get it to work etc
Code:
$var1 = 1;
my %reverse = reverse %hash;
if( defined( $reverse{$var1} ) ) {
print "1 is a value in the hash!\n";
}
else {
print "1 is not a value in the hash!\n";
}