You are correct that $foo and $crew[0] are both references to the same hash. Case 2 (in the document) is messy, but it has the advantage that it can correctly dereference any reference (including both of these)

Code

print ${$crew[0]}{'name'}; print ${$foo }{'name'};

Your working examples are examples of other cases. They are both convenient, but you must read very carefully to be sure when they can be used. Good Luck, Bill

When you place the braces { } next to $foo, it means this should be a hash %foo.

When you place braces next to an array element and the contents of the array item is a reference, Perl treats it like a sequence of references (multi dimensional array). The -> arrow is optional when items are references.

$crew[0] is actually a reference to the array @crew index offset 0.

These are all equivalent: $crew[0]->{name} ${$crew[0]}{name} $crew[0]{name} (preferred)

The $foo variable is storing a Hash reference, Perl does not auto deref it. So you need to dereference it.

These are all equivalent: ${$foo}{name} $$foo{name} $foo->{name} (preferred)

$crew[0]{name} is equivalent to $foo->{name}

Example: $array[0][1]{name}[3]{test} can be written $array[0]->[1]->{name}->[3]->{test}

If $crew was an array ref to an anonymous array $crew = [ \%gilligan_info ];

$crew->[0]{name} or $crew->[0]->{name}

Also, using braces when dereferencing is recommended.

${ } @{ } %{ }

Once you construct more complex structures, you will need to isolate the elements that need dereferencing

They each contain a reference to the hash %gilligan_info, which I believe is what the OP meant by

Quote

given that $foo and $crew[0] are the same thing

My code verifies this by dereferencing both of them with the same syntax. (Case 2 from the referenced document)

All of the working examples from both you and the OP are alternate syntaxes documented in the same section of the document. I usually use the case 2 syntax in my own work because it always works.Good Luck, Bill