I had to truncate the input since there are not enough entries in the sample hash.#!/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
In reply to Re^3: Using Hashes to replace values
by choroba
in thread Using Hashes to replace values
by b00mIR
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |