in reply to CSV column names
If you haven't enabled skip_first_row (you have not in this script) and info.csv has all of the column names defined in the first row then you should be able to use col_names.
I just threw this together. It is untested!
#!/bin/env perl use strict; use warnings; use DBI; my $dbh = DBI->connect('DBI:CSV:'); $dbh->{csv_tables}{info} = { file => 'info.csv' }; my $qu = $dbh->prepare('select * from info'); $qu->execute(); my @cols = @{$dbh->{csv_tables}{info}{col_names}}; # col_names won't b +e defined until you've queried the file. print "column names: @cols\n"; while( my @row = $qu->fetchrow_array) { print "row: @row\n"; }
Update: Corrected script.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CSV column names
by Marshall (Canon) on Aug 23, 2016 at 21:45 UTC | |
by Mr. Muskrat (Canon) on Aug 23, 2016 at 22:14 UTC | |
|
Re^2: CSV column names
by Anonymous Monk on Aug 27, 2016 at 10:49 UTC | |
by erix (Prior) on Aug 27, 2016 at 11:04 UTC | |
by Anonymous Monk on Aug 27, 2016 at 11:27 UTC | |
by Mr. Muskrat (Canon) on Aug 29, 2016 at 13:51 UTC |