rkenshin09 has asked for the wisdom of the Perl Monks concerning the following question:

Hey, I'm trying to perform a global search for a DNA sequence, and have a predefined hash that matches a key to a DNA site. However, this DNA site has the DNA sequence followed by a location modifier as the string (ie $A => 'AATCAA 2'). What's the easiest command/search string to just search globally for the dna sequence? Thanks in advance.

Replies are listed 'Best First'.
Re: hashes help
by GrandFather (Saint) on Sep 25, 2008 at 03:14 UTC

    You don't give us much code to go on! Maybe you need to invert the hash so that you can do a reverse look up? Something like:

    use strict; use warnings; use Data::Dump::Streamer; my %dnaLookup = ( wibble => 'AATCAA 2', wobble => 'AATCAA 1', plibble => 'GATCAA 3', plobble => 'GATCAA 1', ); my %reverseLookup; for my $key (keys %dnaLookup) { my ($dna, $loc) = split ' ', $dnaLookup{$key}; push @{$reverseLookup{$dna}}, [$key, $loc]; } Dump (\%reverseLookup);

    Prints:

    $HASH1 = { AATCAA => [ [ 'wibble', 2 ], [ 'wobble', 1 ] ], GATCAA => [ [ 'plobble', 1 ], [ 'plibble', 3 ] ] };

    Perl reduces RSI - it saves typing