0
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};}

私のコードは上に示されています。エラーメッセージが表示されます:

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

ただし、関数は引き続き実行可能です。そして、残りはすべて問題ないようです。では、このエラーは何について話しているのでしょうか? そして、どうすれば修正できますか?ありがとう。

4

1 に答える 1

5

投稿したコードでは、その警告は表示されません。フォームのコード

%foo->{bar}

その警告を与えます。として機能するため、その警告が表示されます

$foo->{bar}

するべきではないのに。


$ 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
于 2012-05-22T16:30:20.787 に答える