my @array = ( 1, 2, 3 );
for my $elem ( @array ){
say $elem;
}
####
my $aref = \@array;
##
##
ARRAY(0x9bfa8c8)
##
##
for my $elem ( @{ $aref } ){
say $elem;
}
##
##
my $x = $array[0];
##
##
my $y = $aref->[1];
##
##
$array[1] = "assigning to array element 2";
##
##
$aref->[1] = "assigning to array element 2";
##
##
my %hash = ( a => 1, b => 2, c => 3 );
while ( my ( $key, $value ) = each %hash ){
say "key: $key, value: $value";
}
##
##
my $href = \%hash;
##
##
while ( my ( $key, $value ) = each %{ $href } ){
say "key: $key, value: $value";
}
##
##
my $x = $hash{ a };
##
##
my $y = $href->{ a };
##
##
$hash{ a } = "assigning to hash key a";
##
##
$href->{ a } = "assigning to hash key a";
##
##
my @array = ( 1, 2, 3 );
my $aref = \@array;
# assign a new value to $b[0] through the reference
$aref->[0] = 99;
# print the array
for my $elem ( @array ){
say $elem;
}
##
##
99
2
3
##
##
$array[0] = 99;
$aref->[0] = 99;
##
##
my @array = ( 1, 2, 3 );
my %hash = ( a => 1, b => 2, c => 3 );
# take a reference to the array
my $aref = \@array;
# take a reference to the hash
my $href = \%hash;
# access the entire array through its reference
my $elem_count = scalar @{ $aref };
# access the entire hash through its reference
my $keys_count = keys %{ $href };
# get a single element through the array reference
my $element = $aref->[0];
# get a single value through the hash reference
my $value = $href->{ a };
# assign to a single array element through its reference
$aref->[0] = 1;
# assign a value to a single hash key through its ref
$href->{ a } = 1;