Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
but I wanted to ask, does this code check also if any key of hash2 is in hash1? Or must I write it again so as to get the keys of hash2 that are present in hash1?my @common = (); foreach (keys %hash1) { push(@common, $_) if exists $hash2{$_}; } # @common now contains common keys
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: common keys in two hashes
by olus (Curate) on Jan 09, 2008 at 17:32 UTC | |
by Anonymous Monk on Jan 09, 2008 at 17:58 UTC | |
by toolic (Bishop) on Jan 09, 2008 at 18:09 UTC | |
by alexm (Chaplain) on Jan 09, 2008 at 18:05 UTC | |
by WoodyWeaver (Monk) on Jan 09, 2008 at 20:16 UTC |