Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: how extract values of hash via key

by hippo (Vicar)
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.


Comment on Re: how extract values of hash via key
Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2015-07-07 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls