in reply to Hash syntax
Look at the difference that dereferencing with the first -> makes:
Output:use strict; use warnings; use feature 'say'; my $hash_ref = {}; # SCALAR pointing to an empty HASH reference my %hash = (); # actual HASH $hash{key1}{key2} = 'val1'; $hash_ref->{key1}->{key2} = 'val2'; $hash_ref = { # HASH reference, note: curly brace *** key1 => { # key1 is a nested HASH reference key2 => 'val2', # key2 is pointing to the value "val2" }, }; %hash = ( # actual HASH, note: parens *** key1 => { # key1 is a nested HASH reference key2 => 'val1', # key2 is pointing to the value "val2" }, ); # accessing "key2" in $hash_ref: say $hash_ref->{key1}->{key2}; # the first "->" is important say $hash_ref->{key1}{key2}; # accessing "key2" in %hash: say $hash{key1}{key2}; # lack of the first "->" is important say $hash{key1}->{key2}; __END__
To underscore the difference also, you can look at how an a HASH can be assigned with an even sized list,val2 val2 val1 val1
Output:my @hash = ("key3", "val3", "key4", "val4"); # actual ARRAY my %hash3 = @hash; # even sized (2, 4, etc) list assignment works say $hash3{key3}; say $hash3{key4};
val3 val4
|
|---|