Hi Om, In addition to what Rob wrote: On Tue, Apr 3, 2012 at 10:38 AM, Om Prakash <oomprak...@gmail.com> wrote:
> Hi all, > > I have some data which is like > > A:12 > B:13 > C: 14 > > Now the data is line by line and multiple line with A B C is common though > 12 13 14 is changing, i want to take this data column wise, and the the > value should come under A B C. Any help will be appreciated. > If what you wanted is to display changing values of A B and C collectively under the heading A, B and C, the script below could help out. Am using the data provided by Rob.... #!/usr/bin/perl use warnings; use strict; my %hash; open my $fh, '<', 'input.file' or die "can't open file because: $!"; while(<$fh>){ chomp; my($letter,$num)=split/:/,$_; $hash{$letter}=[] unless exists $hash{$letter}; push @{$hash{$letter}},$num; } close $fh; foreach my $let(sort keys %hash){ print $let,$/; foreach my $num(@{$hash{$let}}){ print "\t",$num,$/; } } **OUTPUT** A 12 1 34 B 13 2 C 14 54 > Regards.../om > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- Tim