Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is there a bind_hash()?

2 views
Skip to first unread message

Todd Hepler

unread,
Dec 1, 2005, 7:17:29 PM12/1/05
to dbi-...@perl.org
Hi all,

Is there a CPAN module out there that implements something like
bind_hash() from this article:

http://www.perl.com/pub/a/2001/03/dbiokay.html

My searches aren't coming up with anything.

Basically I'm looking for something like this snippet:

@results{@fields} = ();
$sth->bind_columns(map { \$results{$_} } @fields);

wrapped in a nice little interface.

Thanks,
-Todd

John Siracusa

unread,
Dec 1, 2005, 7:31:11 PM12/1/05
to DBI Users
On 12/1/05 7:17 PM, Todd Hepler wrote:
> Basically I'm looking for something like this snippet:
>
> @results{@fields} = ();
> $sth->bind_columns(map { \$results{$_} } @fields);
>
> wrapped in a nice little interface.

Just an unrelated tip: the above can be done a bit more idiomatically (and
probably a teeny bit faster) like this:

$sth->bind_columns(\@results{@fields});

-John


John Moon

unread,
Dec 1, 2005, 7:22:24 PM12/1/05
to Todd Hepler, dbi-...@perl.org
Subject: is there a bind_hash()?

Hi all,

Is there a CPAN module out there that implements something like
bind_hash() from this article:

http://www.perl.com/pub/a/2001/03/dbiokay.html

My searches aren't coming up with anything.

Basically I'm looking for something like this snippet:

@results{@fields} = ();
$sth->bind_columns(map { \$results{$_} } @fields);

wrapped in a nice little interface.

Thanks,
-Todd

Have you looked at fetchrow_hashref or fetchall_hashref?

jwm

Tim Bunce

unread,
Dec 2, 2005, 7:20:30 AM12/2/05
to John Siracusa, DBI Users

Which is very like the example in the DBI docs for the bind_columns method:

$sth->execute;
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
while ($sth->fetch) {
print "$row{region}: $row{sales}\n";
}

I hope you'll agree, Todd, that there's no need for an extra module.
CPAN has more than enough DBI helper/wrapper modules already.

Tim.

Todd Hepler

unread,
Dec 2, 2005, 8:52:44 AM12/2/05
to Tim Bunce, DBI Users
Tim Bunce wrote:
>
> I hope you'll agree, Todd, that there's no need for an extra module.
> CPAN has more than enough DBI helper/wrapper modules already.
>

Thanks for setting me straight.

-Todd

0 new messages