[Bangalore-pm] help in scripting

Venkatesh N nvenkatesh.27 at gmail.com
Sat Apr 16 23:52:24 PDT 2011


Hi,

Another solution to the problem,

pgm.pl :

use strict;

my %h;

while(<>) {
   chomp;
   @a = split(/ /);
   $h{$a[0]} = $h{$a[0]}." ".$a[1];
}

foreach my $key(sort keys %h) {
   print "$key $h{$key}\n";
}

Execute the above program with the data file as the command line argument.

perl pgm.pl data.txt

Thanks,
Venkatesh N

2011/4/16 Jagadeesh N. Malakannavar <mnjagadeesh at gmail.com>

> please find attached files.  if you still have difficulties getting this
> code running let me see your code.
>
>
> Thanks
>
>
> On Sat, Apr 16, 2011 at 12:13 PM, Gurunath Katagi <
> gurunath.katagi at gmail.com> wrote:
>
>> hi ..
>> how r u reading the a list of values into a scalar ..
>> when i tried this, its taking only one value ..
>> please find the input file attached ..
>>   and kindly reply ..
>>
>> Thank you
>> gurunath
>>
>>
>>
>> On Sat, Apr 16, 2011 at 11:19 AM, Jagadeesh N. Malakannavar <
>> mnjagadeesh at gmail.com> wrote:
>>
>>> 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
>>>>
>>>
>>>
>>
>
>
> --
>
> Thanks,
> Jagadeesh N.Malakannavar
> 9448471968
>
>
> _______________________________________________
> 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/20110417/c3ede6ab/attachment.html>


More information about the Bangalore-pm mailing list