12/13/2017 - 12:55 PM

Anon Array and Hash References

This is done by simply surrounding the list-producing expression with square brackets. It behaves the same as named a named array reference, except the array brackets always create a new reference.

# Example:
my @meals = qw(soup sandwiches pizza);
my $sunday_ref = \@meals;
my $monday_ref = \@meals;

push @meals, 'ice cream sundae';  
\!h # both references contain a dessert, whereas:

my $sunday_ref = [@meals];
my $monday_ref = [@meals];

push @meals, 'berry pie'; 
\!h # neither $sunday_ref nor $monday_ref contains a dessert
# within those square brackets, list context flattens the @meals array into a list unconnected to @meals

\!h # Hashes: use parentheses for a named hash and curly brackets for an anonymous hash