in reply to Using Hashes to replace values

I do not get it. Can you show the desired output for your sample input? Also, can you explain where the hash key comes from and what its relation to the data is?

Replies are listed 'Best First'.
Re^2: Using Hashes to replace values
by b00mIR (Initiate) on Mar 07, 2012 at 12:04 UTC

    my desired output would be like this

    # ID 1005.csv C A C C A G G G G A C A A A A G G A etc.. C A C C A G G T G A C A C G G G A G etc.. etc...

    the hash extends on for about another 1300 keys or so and the file that is being changed has about 800 more IDs<\p>

      #!/usr/bin/perl use warnings; use strict; my %hash = ( '5302' => [qw/C T/], '9046' => [qw/G A/], '11110' => [qw/T C/], '12640' => [qw/T C/], '18262' => [qw/A G/], '21994' => [qw/A G/], '25713' => [qw/A G/], '26638' => [qw/T G/], '28194' => [qw/A G/], '29841' => [qw/G A/], '30475' => [qw/T C/], '31503' => [qw/A C/], '32211' => [qw/G A/], '37138' => [qw/G A/], '41088' => [qw/G A/], '42626' => [qw/A G/]); my @keys = sort { $a <=> $b } keys %hash; while (<DATA>) { unless (index $_, '#') { print; next; } my $idx = 0; print join ' ', map {$hash{ $keys[$idx++] }[$_]} split; print "\n"; } __DATA__ # ID 1005.csv 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 1 1 0 0 0 0 0 # ID 1009.csv 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0
      I had to truncate the input since there are not enough entries in the sample hash.