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.
精彩评论