Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how extract values of hash via key

by hippo (Monsignor)
on Nov 22, 2013 at 09:47 UTC ( #1063909=note: print w/replies, xml ) Need Help??


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 (Prior) on Nov 22, 2013 at 10:19 UTC

    grep is doing the job nicely:

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063909]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2016-12-03 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (55 votes). Check out past polls.