2012-05-22 57 views
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};} 

我的代碼如上所示。它給我的錯誤信息:perl中的錯誤:不推薦使用散列作爲參考

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

但是,功能仍然可運行。其餘的都很好。那麼這個錯誤在談論什麼?我該如何解決它?謝謝。

+0

顯示整個代碼,特別是變量是如何填充數據結構的一部分。 – daxim

+1

您可以通過以下方式檢查此錯誤:perldoc perldiag – quicoju

+0

將「使用診斷」添加到您的代碼中。 –

回答

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