Using hash as a reference is deprecated

hash, perl

Solution

The correct way to access an element of hash `%name` is `$name{'key'}`. The syntax `%name->{'key'}` was valid in Perl v5.6 but has since been deprecated.

Similarly, to access the last element of array `@id` you should write `$id[$#id]` or, more simply, `$id[-1]`.

Your second variation should work fine, and your inability to retrieve the value has an unrelated reason.

Write

$name{$id[-1]} = 'test';

and

print $name{$id[-1]};

will display `test` correctly

Problem

I searched SO before asking this question, I am completely new to this and have no idea how to handle these errors. By this I mean Perl language. When I put this ``` %name->{@id[$#id]} = $temp; ``` I get the error `Using a hash as a reference is deprecated` I tried ``` $name{@id[$#id]} = $temp ``` but couldn't get any results back. Any suggestions?

Original source

Related problems