Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Which actually looks like this if comma separated1234522 1567811 18810122 2133443 2455613 this would continue further toaround1000's of lines
I have the first column as a key and rest in a array as values.1,23,45,2,2 1,56,78,1,1 1,88,101,2,2 2,13,34,4,3 2,45,56,1,3
I would like to insert rows, so that there is no gaps in the sequence, and is continuous until it finishes the particular key>say 1/2.1,1,22,2,2 1,23,45,2,2 1,46,55,2,2 1,56,78,1,1 1,79,87,2,2 1,88,101,2,2 2,1,12,2,2 2,13,34,4,3 2,35,44,2,2 2,45,56,1,3
!/software/bin/perl use strict; use warnings ; while(<>){ my @line = split(/,/,$_); my @splice = splice(@line, 3,8); my $chr = shift @splice;#shifts the first element my %hash; $hash{$chr} = \@splice; foreach my $key (sort keys %hash){ print $key, "," , $hash{$key}[0] ,",", $hash{$key}[1], "\n"; } }
Thanks a lot in advance,The input would be: 1,34,1,23,45,2,2 35,45,1,56,78,1,1 46,56,1,88,101,2,2 57,68,2,13,34,4,3 69,78,2,45,56,1,3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: adding the missing sequence numbers
by ikegami (Patriarch) on Jan 19, 2011 at 17:49 UTC | |
|
Re: adding the missing sequence numbers
by jethro (Monsignor) on Jan 19, 2011 at 18:08 UTC | |
by ikegami (Patriarch) on Jan 19, 2011 at 18:33 UTC | |
by jethro (Monsignor) on Jan 19, 2011 at 19:16 UTC | |
by remiah (Hermit) on Jan 20, 2011 at 04:19 UTC |