#!/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_Memory_Pages_sec) FROM results"); my $file = 'test.csv'; my $csv = Text::CSV->new(); open (CSV, "<", $file) or die $!; while () { 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\($field\) FROM results\"\) \n"); $avg = $dbh->prepare("SELECT avg($field) FROM results"); print ("$field, $avg \n"); } ###print ("$avg,\n"); close CSV;