Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...