#!/usr/bin/perl use DBI; use warnings 'all'; use strict; my $dbh = DBI->connect(...) || die("could not create handler: ", $DBI::errstr); my $sth = $dbh->prepare(q{ SELECT Name, Price, Description FROM Products ORDER BY Name, Price }) || die("could not prepare product listing: ", $dbh->errstr); $sth->execute || die("could not execute product listing: ", $sth->errstr); my($name, $price, $description); $sth->bind_columns(\($name, $price, $description)); while($sth->fetch) { print "
##
# ... assume up to $sth->execute
$sth->bind_columns(
map { \${$_} }
@{ $sth->{NAME_lc} }
) || die("unable to bind columns: ", $sth->errstr);
# ... assume same while-loop and output as before
####
#!/usr/bin/perl
use DBI;
use warnings 'all';
use strict;
no strict 'refs'; # Ni!
my $dbh = DBI->connect(...)
|| die("could not create handler: ", $DBI::errstr);
my $sth = $dbh->prepare(q{
SELECT Name, Price, Description
FROM Products
ORDER BY Name, Price
}) || die("could not prepare product listing: ", $dbh->errstr);
$sth->execute
|| die("could not execute product listing: ", $sth->errstr);
$sth->bind_columns(
map { \${"main::$_"} } # `my' isn't going to cut it
@{ $sth->{NAME_lc} } # who knows where this is going to run?
) || die("unable to bind columns: ", $sth->errstr);
while($sth->fetch) {
print "$name $price \n";
print "$description \n";
}