in reply to Re^3: array of hash
in thread array of hash

I don't want to build. I already build %currHash and then, want to assign the whole %currHash to the 3rd array element of %curr. Then, I will change the value of the keys of the hash which is the 3rd element of array of %curr but I don't want that %currHash gets changed

If I do such assignment, how come that the value of the CD doesn't exist when assigning %currHash or %tmp?

Replies are listed 'Best First'.
Re^5: array of hash
by choroba (Cardinal) on May 27, 2014 at 12:42 UTC
    You have to change the way you build the structure, because it's the source of the problem. Please read all the comments and linked pages again to understand.

    push @currArr, %currHash;

    This line does not insert a hash into an array. It flattens the hash to a list to be inserted. Use Data::Dumper to visualize the resulting structures. What structure do you exactly want to build? If you want to create a copy of a shallow hash, use

    push @currArr, { %currHash };

    To create a deep copy, see Clone or Storable.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ