On Sat, Apr 16, 2011 at 11:36 AM, 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
>



HI

 i am not sure here is what  you want done but  , here is what i came up with .

#!/usr/bin/perl

use strict;
use warnings ;
use Data::Dumper;


my $filename = $ARGV[0];

my (%tag,$dkey,$dval);
open(INPUT_FILE, $filename)  or die "cannot opnen file $!";

while (<INPUT_FILE>) {
  m/(\d+)\s+(\d+)$/;

push (@{$tag{$1}}, $2);


}

close(INPUT_FILE);


foreach my $key ( keys %tag ) {
print "$key  --> @{$tag{$key}}\n";

}


 Except in your question  you mentioned  that you require 99 in  the
2nd and 3rd line also ,  was that a type error .

> 16 50 30 23
> 17 88 99
> 18 99 1







-- 
Regards
Agnello D'souza

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to