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

When you assign to @AoH directly
@AoH = ...

the previous contents of the @AoH is irrelevant, the array now contains different elements. When you assign to something an elements references to, it changes the thing being referenced.

($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,

Replies are listed 'Best First'.
Re^6: Put references to array of hash elements in an array
by tel2 (Pilgrim) on Aug 03, 2018 at 09:50 UTC
    Thanks choroba,

    > "When you assing to @AoH directly (@AoH = ...) the previous contents of the @AoH is irrelevant, the array now contains different elements."

    Where in my code did I assign anything to @AoH directly via "@AoH = ..." apart from at the very beginning?

      Sorry, you assigned to @age_ref directly.
      while (@age_ref = \$sth->fetchrow_array)
      ($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,
        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?