Hi. On 16 April 2011 16:06, Gurunath Katagi <gurunath.kat...@gmail.com> wrote: > hi .. i am new to perl .. > i have a input file something pasted as below .. > > 16 50 > 16 30 > 16 23 > 17 88 > 17 99 > 18 89 > 18 1 > .. > -- > > and i want the output something like this : > 16 50 30 23 > 17 88 99 > 18 99 1 > > i.e for each values in the first column, i want the elements in the second > column to be a one row .. > > can be anybody give me psuedocode , to how to go about this .. > thank you
[isg@tarzan:perl]# cat -n foo.pl 1 #!/usr/bin/env perl 2 use warnings; 3 use strict; 4 use Data::Dumper; 5 open FH,"<", "/tmp/foo" || die "aww... $!"; 6 my $i = {}; 7 while(<FH>) 8 { 9 chop; 10 my ($key, $value) = split(/\space/,$_); 11 push $@{$i->{$key}},$value; # push $value into $i->{$key} 12 } 13 close FH; 14 local $Data::Dumper::Sortkeys = 1; 15 print Dumper($i); [isg@tarzan:perl]# ./foo.pl $VAR1 = { '16' => [ 'i', '<3', 'Python' ], '17' => [ 'but', 'i' ], '18' => [ 'do', 'Perl' ], '19' => [ 'too' ] }; Cheers. -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/