tel2 has asked for the wisdom of the Perl Monks concerning the following question:
What am I doing wrong, please?@AoH = ( { name => Adam, age => 0 }, { name => Bob, age => 10 }, { name => Cat, age => 20 } ); # Trying something simple first (2 scalars on the left of the assignme +nt) ($age_ref0,$age_ref2) = (\$AoH[0]{age},\$AoH[2]{age}); print "\$\$age_ref0 = $$age_ref0\n"; # Prints '$$age_ref0 = 0' print "\$\$age_ref2 = $$age_ref2\n"; # Prints '$$age_ref2 = 20' $$age_ref2 = 21; print "\$\$age_ref2 = $$age_ref2 = $AoH[2]{age}\n"; # The above prints '$$age_ref2 = 21 = 21' # The above went to plan, so but let's try to do similarly using an ar +ray on the left of the assignment @age_ref = (\$AoH[0]{age},\$AoH[2]{age}); print "\$\$age_ref[1] = $$age_ref[1] = @$age_ref[1] = $AoH[2]{age}\n"; # The above prints '$$age_ref[1] = = = 21'. Why??? print Dumper(\@age_ref); # (Essentially) prints: '\0, \21'
Thanks.
tel2
|
|---|