开发者

Why do I get "Pseudo-hashes are deprecated"?

开发者 https://www.devze.com 2023-02-15 12:40 出处:网络
I have this code if (defined($xml->{account}->{p}) == \'2\') { ... } which gives me this warning 开发者_Python百科

I have this code

if (defined($xml->{account}->{p}) == '2') {
...
}

which gives me this warning

开发者_Python百科
Pseudo-hashes are deprecated at a.pl line 48.

The problem is that in some cases $xml->{account}->{p} doesn't exist, which was why I added the defined function.

$xml is an object, if that makes a difference?

How can this be fixed, so Perl doesn't complain?


Either $xml or $xml->{account} is an ARRAY, not a HASH (you can use ref to check this, see perldoc -f ref). Perl had a now-deprecated feature called "pseudo-hashes" that allowed special arrays to be accessed via hash syntax. If you care about the history, you can google around for it or look at an older-edition camel book.

0

精彩评论

暂无评论...
验证码 换一张
取 消