in reply to DBI::CSV using a variable to request columns

You're trying to populate $columns before you've even populated $row out of the DB. You need to do this within the while() loop (perhaps with a count variable so that it only runs on the first pass). Also, you declare $queryResult, but then later use it in a very strange way.

What is your goal for $queryResult? Is it to add the headers, then append details from every row?

Replies are listed 'Best First'.
Re^2: DBI::CSV using a variable to request columns
by Sandy_Bio_Perl (Beadle) on May 20, 2016 at 15:01 UTC

    I suspect my novice skills are beginning to show! I want the user, probably via a web based form, to be able to create a query e.g. select records from men infected with viral genotype a and display user defined results such as subject ID, gender, test group, viral dna levels etc (e.g. the columns)

    I thought that I might display $queryResult in a web page.

      DBI can give you the column names, but only after the ->execute, you can find this e.g. in the doc's section on Statement Handle Attributes.
      I thought that I might display $queryResult in a web page.
      For this purpose, you could use HTML::Table::FromDatabase, which could replace your while loop with a simple call to
      my $table = HTML::Table::FromDatabase->new( -sth => $sth, -html => 'escape', -border => 1, ); print "<html><head><title>this is the page title</title></head><body>< +h1>this is the header</h1>"; print $table->getTable; print "this is the end</body></html>";

        Thank you, brother soonix. Your ontological knowledge knows no bounds. er.. have I gone to far with the whole Monastery/Anselmian stuff..

        Thank you, Corion. That looks like a very useful module.