English 中文(简体)
在 perl 中错误: 使用散列作为引用被折旧
原标题: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};}

我的代码在上面显示。 它给了我错误信息:

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

然而, 函数仍然是可运行的 。 所有的休息都似乎都很好 。 这个错误在说什么? 我该如何修正它? 谢谢 。

问题回答

您张贴的代码没有发出警告。 格式代码

%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




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签