Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: Using a hash as a reference is deprecated

Tags:

perl

I'm developing script, that is reusing some really old piece of perl code.

This line gives me still the error Using a hash as a reference is deprecated .

  %hash->{$_[$counter]} = $_[$counter+1];

How I have to refactor this code, so that I will be not receiving the error.

like image 577
Mejmo Avatar asked Jun 07 '11 13:06

Mejmo


2 Answers

Try

$hash{$_[$counter]} = $_[$counter+1];
like image 197
cnicutar Avatar answered Nov 07 '22 07:11

cnicutar


What's to the left of ->{ should be a hash reference, not a hash. If you have a hash, omit the -> and just say $hash{.

Pedantically, %hash->{...} should do what (my $temp=%hash)->{...} does: get the scalar value of %hash (e.g. "1/8", indicating 1 of 8 buckets used) and use that as a symbolic hash reference (failing with an error under use strict "refs"). But due to an accident, it was quietly reinterpreted as $hash{...} instead. This bug will be fixed some day, but in the meantime people are being warned to change their incorrect code.

like image 23
ysth Avatar answered Nov 07 '22 07:11

ysth