Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: how extract values of hash via key

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

    grep is doing the job nicely:

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2017-12-17 12:22 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (464 votes). Check out past polls.