Think about a data structure called a Hash of Array..
#!/usr/local/bin/perl
use strict;
use warnings;
my %hash;
while(<DATA>){
chomp;
my ($SNP, $IND, $COL1, $COL2, $COL3)= split(/\s+/);
push @{$hash{$IND}}, $COL1, $COL2 if $IND;
}
use Data::Dumper;
print Dumper(\%hash);
__DATA__
SNP5 IND1 A5 C5 0.8
SNP2 IND1 A2 C2 0.8
SNP1 IND1 A1 C1 0.8
SNP3 IND1 A3 C3 0.8
SNP4 IND1 A4 C4 0.8
SNP5 IND2 G5 T5 0.8
SNP2 IND2 G2 T2 0.8
SNP1 IND2 G1 T1 0.8
SNP3 IND2 G3 T3 0.8
SNP4 IND2 G4 T4 0.8
check
The Data Structure Cookbook.
sorting and printing the outcome is left as an exercise to the OP
Excellence is an Endeavor of Persistence.
Chance Favors a Prepared Mind.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.