in reply to Hash to Array assignment?
Consider:
#! perl use strict; use warnings; use Data::Dump; my %hash1 = ( fred => [ 'wilma', 'pebbles' ], barney => [ 'betty', 'bamm-bamm' ], ); my %hash2 = ( homer => [ 'marge', 'bart', 'lisa', 'maggie' ], romeo => [ 'juliet' ] ); my $a = 'fred'; my $b = 'homer'; print "Before the assignments:\n"; print "hash1: "; dd \%hash1; print "hash2: "; dd \%hash2; my $sub = $hash1{$a} = $hash2{$b}; print "\nAfter the assignments:\n"; print "hash1: "; dd \%hash1; print "hash2: "; dd \%hash2; print "sub: "; dd $sub; push @$sub, $a; print "\nAfter the push:\n"; print "sub: "; dd $sub;
Output:
12:39 >perl 765_SoPW.pl Before the assignments: hash1: { barney => ["betty", "bamm-bamm"], fred => ["wilma", "pebbles" +] } hash2: { homer => ["marge", "bart", "lisa", "maggie"], romeo => ["juli +et"] } After the assignments: hash1: { barney => ["betty", "bamm-bamm"], fred => ["marge", "bart", "lisa", "maggie"], } hash2: { homer => ["marge", "bart", "lisa", "maggie"], romeo => ["juli +et"] } sub: ["marge", "bart", "lisa", "maggie"] After the push: sub: ["marge", "bart", "lisa", "maggie", "fred"] 12:39 >
First, the %hash2 value with key $b is assigned to the %hash1 value with key $a.
Next, this value (which in my example code is an array reference) is assigned to $sub.
Finally, $a is pushed onto the array referenced by $sub.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|