#!/user/bin/perl -w use strict; use Data::Dump qw[pp]; $|=1; my %hash; print "** Example 1 ***\n"; #pretty normal thing to do for my $set('A'..'B') { my @array1 = map { int(rand(100)) }(1..2); my @array2 = map { int(rand(100)) }(1..5); $hash{$set} = [ [@array1], [@array2] ]; } pp \%hash; print "** Example 2 ***\n"; #a pitfall here for my $set('G'..'H') { my @array1 = map { int(rand(100)) }(1..2); my @array2 = map { int(rand(100)) }(1..5); $hash{$set} = [ \@array1, \@array2 ]; } pp \%hash; print "** Example ***3\n"; #the wrong thing to do my @x; my @y; for my $set('X'..'Y') { @x = map { int(rand(100)) }(1..2); @y = map { int(rand(100)) }(1..5); $hash{$set} = [ \@x, \@y ]; } pp \%hash; __END__ ** Example 1 *** { A => [[45, 13], [77, 53, 52, 21, 23]], B => [[38, 27], [4, 59, 52, 4, 83]], } ** Example 2 *** { A => [[45, 13], [77, 53, 52, 21, 23]], B => [[38, 27], [4, 59, 52, 4, 83]], G => [[3, 35], [13, 58, 35, 76, 64]], H => [[26, 39], [34, 91, 99, 74, 97]], } ** Example ***3 do { my $a = { A => [[45, 13], [77, 53, 52, 21, 23]], B => [[38, 27], [4, 59, 52, 4, 83]], G => [[3, 35], [13, 58, 35, 76, 64]], H => [[26, 39], [34, 91, 99, 74, 97]], X => [[31, 63], [72, 71, 10, 80, 76]], Y => ['fix', 'fix'], }; $a->{Y}[0] = $a->{X}[0]; $a->{Y}[1] = $a->{X}[1]; $a; }