Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: how extract values of hash via key

by hippo (Curate)
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 (Parson) 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 lurking in the Monastery: (10)
As of 2014-08-28 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls