http://www.perlmonks.org?node_id=284450


in reply to DBI recipes

Nice. ++.

A variation on the hash-binding theme is to use the contents of the statement handles NAME attributes as the hash keys. Since in most instances you'll be interested in all the keys you are selecting this can be a useful shortcut. For example (untested code):

my $sth = $dbh->prepare( "SELECT foo, bar, ni from some_table" ); $sth->execute; my %row; $sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } )); while ($sth->fetch) { print "foo = $row{foo}, bar = $row{bar}, ni = $row{ni}\n"; }

In general the NAME attributes of statement handles are useful to avoid duplicating lists of fields in your SQL and in @fields type arrays.