Hi isha,
If you want to manipulate the simple hash, then your hash will be like this,
my %myhash = ( 1 => 'a', 2=> 'b', 3=> 'a', 4=>'c');To manipulate this simple hash, you can do like
use strict; my %myhash = ( 1 => 'a', 2=> 'b', 3=> 'a', 4=>'c'); for my $key (keys %myhash){ if($myhash{$key} eq 'a'){ print "KEY:$key\n"; } }
But you created the hash as
my %myhash = { 1 => 'a', 2=> 'b', 3=> 'a', 4=>'c'};
which is anonymous hash reference. To manipulate this hash reference, then you can do like
use strict; my $myhash = { 1 => 'a', 2=> 'b', 3=> 'a', 4=>'c'}; for my $key (keys %{$myhash}){ if(${$myhash}{$key} eq 'a'){ print "KEY:$key\n"; } }
Punitha
In reply to Re: How to get Keys from hash having same value?
by Punitha
in thread How to get Keys from hash having same value?
by isha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |