Re: Addition of same value
- From: "Rita" <ritu_minda@xxxxxxxxxxx>
- Date: 29 Nov 2005 08:20:36 -0800
Tad McClellan wrote:
> Rita <ritu_minda@xxxxxxxxxxx> wrote:
>
>
> > I want to make programm Which find all the same values from left side
> > and do addition of that value of right side.
>
> > So what will be code for it?
>
>
> ------------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my %nums;
> while ( <DATA> ) {
> my($k, $v) = split;
> $nums{$k} += $v;
> }
>
> foreach ( sort {$a <=> $b} keys %nums ) {
> print "$_ sums to $nums{$_}\n";
> }
>
> __DATA__
> 120.00 14.85
> 125.00 12.53
> 125.00 10.576
> 125.00 15.326
> 127.00 18.245
> 127.00 5.243
> 129.00 10.253
> 132.00 15.02
> 135.00 12.356
> 135.00 12.34
> 135.00 14.35
> 137.00 11.21
> ------------------------------
>
>
Thanks.
.
- References:
- Addition of same value
- From: Rita
- Re: Addition of same value
- From: Tad McClellan
- Addition of same value
- Prev by Date: Re: length is 0 with unpack_socketaddr_in
- Next by Date: Re: performance and timing issues udp socket
- Previous by thread: Re: Addition of same value
- Next by thread: substr forces scalar context with array argument
- Index(es):
Relevant Pages
|