my $sales = {
monday => { jim => [ 2 ], mary => [ 1, 3, 7 ] },
tuesday => { jim => [ 3, 8 ], mary => [ 5, 5 ] },
wednesday => { jim => [ 7, 0 ], mary => [ 3 ] },
thursday => { jim => [ 4 ], mary => [ 5, 7, 2, 5, 2 ] },
friday => { jim => [ 1, 1, 5 ], mary => [ 2 ] },
};
####
my $commissions = $sales->{tuesday}{jim};
my $num_sales = @$commissions;
my $total = 0;
foreach (@$commissions) {
$total += $_;
}
print "Jim made $num_sales sales on Tuesday and earned \$$total commission\n";
####
my @fools = qw(jester clown motley);
my $fools = \@fools;
The $fools variable now contains a reference to the @fools array. You can copy the values to
another array by prepending it with the @ sign (the array sigil).
my @copy_of_fools = @$fools;
To access individual elements of the $fools array reference, you use the same syntax as you would
to access the original array, but you use the dereferencing operator, ->, between the array name and
the square brackets.