开发者

Perl: Using a hash as a reference is deprecated

开发者 https://www.devze.com 2023-03-11 04:40 出处:网络
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 r开发者_开发知识库eference is deprecated .

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 r开发者_开发知识库eference is deprecated .

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

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


Try

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消