CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [lkhlc] Adding Column values and more (not spam thankyou!): Edit Log



Kenosis
User

Dec 2, 2013, 9:33 PM


Views: 3157
Re: [lkhlc] Adding Column values and more (not spam thankyou!)


Code
use strict; 
use warnings;

my ( %hash, @vals );

while (<>) {
chomp;
$hash{ $vals[0] } += $vals[1] if @vals = split /,/;
}

print "$_,$hash{$_}\n" for sort { $a <=> $b } keys %hash;

Usage: perl script.pl inFile >outFIle

Output on your dataset:

Code
04054017280,34 
04054017500,48
04054018280,118


Hope this helps!


(This post was edited by Kenosis on Dec 2, 2013, 9:43 PM)


Edit Log:
Post edited by Kenosis (User) on Dec 2, 2013, 9:33 PM
Post edited by Kenosis (User) on Dec 2, 2013, 9:34 PM
Post edited by Kenosis (User) on Dec 2, 2013, 9:39 PM
Post edited by Kenosis (User) on Dec 2, 2013, 9:39 PM
Post edited by Kenosis (User) on Dec 2, 2013, 9:43 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives