in reply to Re^7: Put references to array of hash elements in an array
in thread Put references to array of hash elements in an array

OK thanks choroba,

Using the @AoH that I have (as it is), is there a way I can rewrite this line:
while (@age_ref = \$sth->fetchrow_array)
so that it replaces the age values in @AoH, maybe using similar principles to those which allow this to update the age values:
($age_ref0,$age_ref2) = (\$AoH[0]{age},\$AoH[2]{age});

If not, what's preventing this?

Replies are listed 'Best First'.
Re^9: Put references to array of hash elements in an array
by choroba (Cardinal) on Aug 03, 2018 at 10:54 UTC
    #!/usr/bin/env perl use warnings; use strict; use feature qw{ say }; my @AoH = ( { age => \ do { my $tmp = 42 } }, {}, { age => \ do { my $mpt = 33 } } ); my @age_ref = \($AoH[0]{age}, $AoH[2]{age}); (${ $age_ref[0] }, ${ $age_ref[1] }) = (1, 2); use Data::Dumper; print Dumper \@AoH;

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thanks choroba,

      Sorry I wasn't clearer about this, but instead of this kind of thing, which you're suggesting:

      (${ $age_ref[0] }, ${ $age_ref[1] }) = (1, 2);
      where I'd have to type out all the variables on the left, I was after something more flexible, i.e. something which can handle any number of variables.  To do this maybe the syntax would have to mention the array (@) itself on the left.

      This is a bit (or even a byte) academic now, because LanX's suggestion of DBI's bind_col() seems to be working for me.  However, I'm not against academia, since it may be useful in the future, but if you don't have any quick & easy ideas, feel free to drop this now, because at least my current problem is sorted.