Edward Wijaya wrote:
I just realize that hash table can only return the values of
"unique" key.

And the compute_ic() function computes numbers that are not unique, so they can't be hash keys, I see. You have a new problem.

We don't know much about the bigger picture here. Would possibly an
array of hashes be a suitable data structure?

use strict;
use warnings;
use Data::Dumper;
do './ic.pl';

my @AoH = (
    { values => ['AGCGGGGAG','AGCGGGGCG','AGCCGGGCG','AGCCAGGAG'] },
    { values => ['AGCGGAGCG','AGCCGAGGG','AGCGGAGGG'] },
);

for ( 0..$#AoH ) {
    $AoH[$_]->{ic} = compute_ic( @{ $AoH[$_]->{values} } );
}

print Dumper @AoH;

__END__
$VAR1 = {
          'values' => [
                        'AGCGGGGAG',
                        'AGCGGGGCG',
                        'AGCCGGGCG',
                        'AGCCAGGAG'
                      ],
          'ic' => '15.1887218755409'
        };
$VAR2 = {
          'values' => [
                        'AGCGGAGCG',
                        'AGCCGAGGG',
                        'AGCGGAGGG'
                      ],
          'ic' => '16.163408331891'
        };


    my %HoA = (
        'A' =>
        [ 'AGCGGGGAG', 'AGCGGGGCG', 'AGCCGGGCG', 'AGCCAGGAG', ],
        'B' =>
            [ 'CGTGCCTCC', 'CGTCCCGCC', 'CGTGCCTCC', 'CGTCCCTCC',],
        ...
    );

 print "Sorted by Values\n";
   for ( sort { $a <=> $b } keys %HoA ) {

That tries to do a numerical sort on keys that are no longer numerical. If you had had warnings enabled (which you should...), Perl would have told you so.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to