in reply to Re: Generation of Array of hashes by reading a file
in thread Generation of Array of hashes by reading a file

Thanks Huck and other Monks. All the solutions work. One of the doubt I had with this, Every time when the line matches the key related to interface, we are making the hash empty and then pushing that on to Array. I was assuming the Array will only contain a list of empty hashes, But not the case when I run the script with your solution. Can you please explain or help me understand the push statement after assigning empty hash to rec

  • Comment on Re^2: Generation of Array of hashes by reading a file

Replies are listed 'Best First'.
Re^3: Generation of Array of hashes by reading a file
by choroba (Cardinal) on Jan 04, 2018 at 23:21 UTC
    $rec is not a hash, it's a hash reference. When you change the referenced hash, all references pointing to it see the new value.

    my $hash_ref = {}; push my @arr, $hash_ref; $hash_ref->{key} = 'value'; print $arr[0]{key}; # value

    ($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. That cleared my confusion around this.