Peamasii has asked for the wisdom of the Perl Monks concerning the following question:
sub print_stats { my($table) = @_; my $sth = $dbh->prepare('SELECT * FROM '.$table) or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute # Execute the query or die "Couldn't execute statement: " . $sth->errstr; my $names = $sth->{NAME}; # or NAME_lc or NAME_uc while( my $report_row = $sth->fetchrow_arrayref() ) { for my $col_idx ( 0 .. $#{$names} ) { print "$names->[$col_idx]: $report_row->[$col_idx]\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: get each column key/value
by roboticus (Chancellor) on May 30, 2015 at 14:49 UTC | |
|
Re: get each column key/value
by afoken (Chancellor) on May 31, 2015 at 07:21 UTC |