问题
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