Perl - Summarize Data in File -


whats best way summarize data file has around 2 million records in perl?

for eg: file this,

abc|xyz|def|egh|100

abc|xyz|def|fgh|200

sdf|ght|www|rty|1000

sdf|ght|www|tyu|2000

needs summarized on first 3 columns this,

abc|xyz|def|300

sdf|ght|www|3000

chris

assuming there 5 columns, fifth of numeric, , want first 3 columns key...

use warnings; use strict;  %totals_hash;  while (<>) {   chomp;   @cols = split /\|/;    $key = join '|', @cols[0..2];    $totals_hash{$key} += $cols[4]; }  foreach (sort keys %totals_hash) {   print $_, '|', $totals_hash{$_}, "\n"; } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -