in reply to Extracting Columns from line
I don’t understand this part of the code:
my $col = ""; foreach my $key (keys %sampleValue){ my @col1 = split("\t",$sampleValue{$key}); $col = $col1[1].",".$col; } chop($col); print $col,"\n"; ## string of all the columns I am interested in
So far as I can see, %sampleValue contains entries of the form Header1 => 1, Header2 => 2, Header5 => 5, ..., so splitting each value on tabs does nothing? In any case, you need to produce an array here, not a string:
my @cols = sort values %sampleValue;
Then you can use an array slice:
## Reading the sample Value file while (<$IN>) { chomp; print $_, "\n"; my @line = split "\t"; @line = @line[@cols]; # <-- Use array slice here ...
Some notes:
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extracting columns from line
by snape (Pilgrim) on Oct 23, 2013 at 02:58 UTC |