in reply to how extract values of hash via key

Keeping your initial declaration of the hash, we can do:

my %CodonMap = ('GCA'=>'A', 'GCC'=>'A', 'GCG'=>'A', 'GCU'=>'A'); my @acodes = (); for my $key (keys %CodonMap) { next unless $CodonMap{$key} eq 'A'; push @acodes, $key; } print join ("\n", @acodes, '');

There's probably a more efficient way, but at least you now have a working algorithm.

Replies are listed 'Best First'.
Re^2: how extract values of hash via key
by hdb (Monsignor) on Nov 22, 2013 at 10:19 UTC

    grep is doing the job nicely:

    my @acodes = grep { $CodonMap{$_} eq 'A' } keys %CodonMap;