in reply to how extract values of hash via key

G'day sahusonu,

Welcome to the monastery.

Your simplest solution might be this:

my %reverse; push @{$reverse{$CodonMap{$_}}}, $_ for keys %CodonMap;

Here's an example with some additional (bogus) data to show this is extensible:

#!/usr/bin/env perl -l use strict; use warnings; my %CodonMap = (GCA=>'A', GCC=>'A', GCG=>'A', GCU=>'A', UVW=>'B', XYZ= +>'B'); my %reverse; push @{$reverse{$CodonMap{$_}}}, $_ for keys %CodonMap; print "A codons: @{$reverse{A}}"; print "B codons: @{$reverse{B}}";

Output:

A codons: GCA GCU GCG GCC B codons: UVW XYZ

-- Ken