[Bangalore-pm] help in scripting

Jagadeesh N. Malakannavar mnjagadeesh at gmail.com
Fri Apr 15 22:49:23 PDT 2011


Here is the sample script . hope this helps you

use strict;
use warnings;

my $str =<<EOF;
16 50
16 30
16 23
17 88
17 99
18 89
18 1
EOF

my $DATA;

while ($str =~ m/\G((\d+)\s+(\d+)\n)/gc) {
    push @{$DATA->{$2}}, $3;
}

foreach my $num (sort keys %$DATA) {
    print "\n$num ", join (' ', @{$DATA->{$num}});
}


----
Thanks
Jagadeesh N.Malakannavar
9448471968

2011/4/16 Gurunath Katagi <gurunath.katagi at gmail.com>

> 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
>
> gurunath
>
> _______________________________________________
> Bangalore-pm mailing list
> Bangalore-pm at pm.org
> http://mail.pm.org/mailman/listinfo/bangalore-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20110416/66563870/attachment.html>


More information about the Bangalore-pm mailing list