Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: perl group by and sort from a csv input file

by Tux (Canon)
on Jul 27, 2017 at 10:09 UTC ( [id://1196154]=note: print w/replies, xml ) Need Help??


in reply to perl group by and sort from a csv input file

Using Laurent_R's hash solution, combined with proper CSV parsing, I'd propose:

use Text::CSV_XS qw( csv ); my %acc; my $aoa = csv (in => "test.csv", on_in => sub { $acc{pack "L>L>", $_[1][0], $_[1][1]} += $_[1][2]; }); csv (in => [ map { [(unpack "L>L>", $_), $acc{$_}] } sort keys %acc ]) +;

Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1196154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found