#!/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.

In reply to Re^3: Using Hashes to replace values by choroba
in thread Using Hashes to replace values by b00mIR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.