Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by Tux (Canon)
on Jul 28, 2017 at 20:15 UTC ( [id://1196233]=note: print w/replies, xml ) Need Help??


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

Then why not use DBD::CSV directly?

$ cat test.csv 3211111,100,3.2 3211112,101,3.2 3211111,100,1.2 3211112,100,2.2 3211113,100,5.2 3211112,100,0.3 $ cat test.pl use 5.18.2; use warnings; use DBI; use Text::CSV_XS qw(csv); my $dbh = DBI->connect ("dbi:CSV:"); $dbh->{csv_tables}{sampleData} = { file => "test.csv", col_names => [qw( sample input amount )], }; csv (in => $dbh->selectall_arrayref (" SELECT sample, input, SUM (amount) FROM sampleData GROUP BY sample, input ORDER BY sample, input")); $ perl test.pl 3211111,100,4.4 3211112,100,2.5 3211112,101,3.2 3211113,100,5.2

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: perl group by and sort from a csv input file
by Your Mother (Archbishop) on Jul 28, 2017 at 20:43 UTC

    Oh, I don't think a DB was necessary at all. But if you're going to use that idiom, it's better, I argue, to put it into a DB so you can use the DB tools. As I think I've said to you before, all ++s to you for your CVS CSV (update: DERPy fingers) related work. :P

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found