Hi Torqued, On Sat, Apr 7, 2012 at 2:20 PM, Torqued <torque.in...@gmail.com> wrote:
> > > Regards.../om > > On 07-Apr-2012, at 15:28, timothy adigun <2teezp...@gmail.com> wrote: > > > 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 > > > > Thanks a lot tim, was wondering how do i take it horizontally. > this is one way: foreach my $let(sort keys %hash){ print $let,': ' ; print join ",",@{$hash{$let}}; print "\n"; } **OUTPUT** A: 12,1,34 B: 13,2 C: 14,54 OR you could use: foreach my $let(sort keys %hash){ print $let,': ' ; foreach my $num(@{$hash{$let}}){ print $num,","; } print "\n"; } **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 > -- Tim