DrAxeman has asked for the wisdom of the Perl Monks concerning the following question:
Great Monks,
I've progressed with my quest for a script to calculate the averages of all columns. However, things are not working like I hoped. The final loop in my script "should" create a SELECT statement to calculate the average of the column (except the first one, but I'll try that later). It isn;t working though.
My output is getting close but looks like
I've progressed with my quest for a script to calculate the averages of all columns. However, things are not working like I hoped. The final loop in my script "should" create a SELECT statement to calculate the average of the column (except the first one, but I'll try that later). It isn;t working though.
My output is getting close but looks like
My script:ERWWCOMMUNITIES_Memory_Pages_sec, DBI::st=HASH(0x853cf7c) ERWWCOMMUNITIES_NetworkInterface_CompaqEthernet_FastEthernetAdapter_Mo +dule_BytesTotalPERsec, DBI::st=HASH(0x85457e8) ERWWCOMMUNITIES_NetworkInterface_MSTCPLoopbackinterface_BytesTotalPERs +ec, DBI::st=HASH(0x8545014)
What am I doing wrong? Is there an easier way than what I've figured out?#!/usr/bin/perl #use strict; use warnings; use DBI; use Text::CSV; # Connect to the database, (the directory containing our csv file( +s)) my $dbh = DBI->connect("DBI:CSV:f_dir=.;csv_eol=\n;"); # Associate our csv file with the table name 'results' $dbh->{'csv_tables'}->{'results'} = { 'file' => 'test.csv'}; #my ($avg) = $dbh->selectrow_array("SELECT avg(ERWWCOMMUNITIES_Mem +ory_Pages_sec) FROM results"); my $file = 'test.csv'; my $csv = Text::CSV->new(); open (CSV, "<", $file) or die $!; while (<CSV>) { next if ($. != 1); if ($csv->parse($_)) { @columns = $csv->fields(); } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } foreach $field (@columns) { ##print ("\$avg \= \$dbh\-\>selectrow_array\(\"SELECT avg\($fi +eld\) FROM results\"\) \n"); $avg = $dbh->prepare("SELECT avg($field) FROM results"); print ("$field, $avg \n"); } ###print ("$avg,\n"); close CSV;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Database processing
by davidrw (Prior) on Aug 06, 2005 at 01:16 UTC | |
by DrAxeman (Scribe) on Aug 06, 2005 at 02:14 UTC | |
by davidrw (Prior) on Aug 06, 2005 at 02:37 UTC | |
by DrAxeman (Scribe) on Aug 06, 2005 at 02:48 UTC | |
by davidrw (Prior) on Aug 06, 2005 at 03:19 UTC | |
| |
by jZed (Prior) on Aug 06, 2005 at 05:38 UTC |
Back to
Seekers of Perl Wisdom