Error in perl: Using a hash as a reference is deprecated

谁都会走 提交于 2019-12-25 05:09:27

问题


sub function{
my $storedata=shift;
my $storenameandaddress=$storedata->{$storeid}->{name}
."_".$storedata->{$storeid}->{location}->{address}
."_".$storedata->{$storeid}->{location}->{city}
."_".$storedata->{$storeid}->{location}->{state}
."_".$storedata->{$storeid}->{location}{country};}

My codes are shown above. and it gives me error message:

Using a hash as a reference is deprecated at main.pl line 141.

However, the function is still runable. And all the rests seem fine. So what is this error talking about? And how should I fix it? Thanks.


回答1:


The code you posted does not give that warning. Code of the form

%foo->{bar}

gives that warning. It gives that warning because it functions as

$foo->{bar}

even though it's not supposed to.


$ perl -wE'my %h = ( foo => 123 ); say %h->{foo};'
Using a hash as a reference is deprecated at -e line 1.
123

$ perl -Mdiagnostics -wE'my %h = ( foo => 123 ); say %h->{foo};'
Using a hash as a reference is deprecated at -e line 1 (#1)
    (D deprecated) You tried to use a hash as a reference, as in
    %foo->{"bar"} or %$ref->{"hello"}.  Versions of perl <= 5.6.1
    used to allow this syntax, but shouldn't have. It is now deprecated, and will
    be removed in a future version.

123

$ perl -wE'my %h = ( foo => 123 ); say $h->{foo};'
123


来源:https://stackoverflow.com/questions/10705876/error-in-perl-using-a-hash-as-a-reference-is-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!