perl中的错误:不建议使用散列作为参考 [英] Error in perl: Using a hash as a reference is deprecated
本文介绍了perl中的错误:不建议使用散列作为参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
子函数{
my $ storedata = shift;
my $ storenameandaddress = $ storedata-> {$ storeid} - > {name}
。_。$ storedata-> {$ storeid} - > {location} - > {address}
。_。$ storedata-> {$ storeid} - > {location} - > {city}
。_。$ storedata-> {$ storeid } - > {location} - > {state}
。_。$ storedata-> {$ storeid} - > {location} {country};}
我的代码如上所示。它给了我错误消息:
在main.pl行141不推荐使用散列作为参考。
但是,该功能仍然可以运行。其余的都很好。那么这个错误在谈论什么?我该如何解决它?谢谢。
解决方案
您发布的代码不会给出该警告。表格代码
%foo-> {bar}
会给出警告。它会发出警告,因为它的功能如下:
pre $ $ foo-> {bar}
即使它不应该。
$ perl -wE'my%h =(foo => 123);例如%h-> {foo};'
在-e第1行不推荐使用散列作为参考。
123
$ perl -Mdiagnostics -wE'my %h =(foo => 123);例如%h-> {foo};'
在-e行1(#1)
(D deprecated)不推荐使用散列作为参考您尝试使用散列作为参考,如
%foo-> {bar}或%$ ref-> {hello}。 perl <= 5.6.1
的版本用于允许这种语法,但不应该有。现在已被弃用,未来版本中将删除
。
123
$ perl -wE'my%h =(foo => 123);说$ h-> {foo};'
123
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.
解决方案
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
这篇关于perl中的错误:不建议使用散列作为参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文