Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

perl - Type of argument to keys on reference must be unblessed hashref or arrayref

    if((scalar keys ($this->{'libraries'}->{$y}->{'cellHash'})) == 0){

This is the line where I am getting the "Type of argument to keys on reference must be unblessed hashref or arrayref" error. Can you help me fix this? I am not posting the code for obvious reasons.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The new ability of keys to take a reference is broken by design. Perl's development team couldn't figure out how it should work with some references, so it only works for some references. As such, keys's ability to accept a reference is documented to be experimental. Unable to resolve this issue, this "feature" was removed in 5.24. You shouldn't use it since your code will stop working when you upgrade your perl.

You've hit on of those case where keys doesn't work when given a reference. Provide a hash or an array instead. In this case, you probably want

keys(%{ $this->{'libraries'}->{$y}->{'cellHash'} })

The whole thing can be written as follows:

if (!keys(%{ $this->{libraries}{$y}{cellHash} })) { ... }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...