Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hash as a reference is deprecated

Tags:

hash

perl

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?

like image 452
Grigor Avatar asked Jun 18 '26 22:06

Grigor


1 Answers

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

like image 95
Borodin Avatar answered Jun 21 '26 12:06

Borodin