in reply to Book Code

It is either a typo on your side, or a printing error in the book. The correct syntax shall be: (it is not {}, but (), as you are defining a hash, not a hash ref)

my %hash = ( Mouse => {Index => 0, Value => 'Jerry'}, Cat => {Index => 1, Value => 'Tom'}, Dog => {Index => 2, Value => 'Spike'} );

If you define a hash ref, not a hash, then you {}, instead of (), the syntax shall be:

my $hash = { Mouse => {Index => 0, Value => 'Jerry'}, Cat => {Index => 1, Value => 'Tom'}, Dog => {Index => 2, Value => 'Spike'} };

But this does not agree with some of the later lines in your script, for example:

foreach (sort {$hash{$a} {'Index'} cmp $hash{$b} {'Index'}} keys %hash +)

Obviously this line expects a hash, not a hash ref.

To retrieve elements from hash ref, you say:

$hash->{$a}