Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Accumulating Column Total for a Particular Key

by jZed (Prior)
on Aug 27, 2007 at 17:17 UTC ( [id://635348]=note: print w/replies, xml ) Need Help??


in reply to Accumulating Column Total for a Particular Key

Since Limbic~Region's excellent response mentions DBD::CSV but then gives an example that doesn't use it, here's an example that does use it:
#!/usr/bin/perl use warnings; use strict; use DBI; my $dbh = DBI->connect( 'dbi:CSV:', undef, undef, {RaiseError=>1,PrintError=>0} ); $dbh->csv_tables->{Log} = { file => 'yourfile.csv' }; my( $oms_cpu_total ) = $dbh->selectrow_array(" SELECT SUM(cpu_minutes) FROM Log WHERE application = ? ",{},'OMS'); printf "Application %s used %d CPU minutes\n", 'OMS',$oms_cpu_time; __END__
Note : you will need to change the column headings to be valid SQL column names. The easiest way is to just change spaces to underscorse, e.g. "cpu_minutes".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found