Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another example to bind columns #159

Open
rwfranks opened this issue Oct 27, 2024 · 0 comments
Open

Another example to bind columns #159

rwfranks opened this issue Oct 27, 2024 · 0 comments

Comments

@rwfranks
Copy link

Transcribed verbatim from CPAN RT#127170, warts and all.

Sat Sep 22 05:17:36 2018 KES [...] cpan.org - Ticket created
Subject: Another example to bind columns

The H.Merijn Brand example to binds columns to the values inside a hash is useful:

$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ))

but has a weakness: If data already fetched call to ->bind_columns will flush current values.

If you want to bind_columns after you have fetched you can use:

use feature 'refaliasing';
no warnings "experimental::refaliasing";
while( my $row =  $sth->fetchrow_arrayref ) {
    \(@$data{ $sth->{NAME_lc}->@* }) =  \(@$row);
}

For older perls:

use Data::Alias;
alias @$data{ $sth->{NAME_lc}->@* } =  @$row;

This is useful in situations when you have many left joins, but wanna to join your %$data hash to only subset of fetched values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant