Type of argument to keys on reference must be unblessed hashref or arrayref
Asked Answered
K

2

6
    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.

Kinser answered 13/6, 2013 at 5:58 Comment(2)
You may not be able to post the real code "for obvious reasons", but how about some sample, runnable, dummy code which demonstrates the issue you're encountering without exposing the full context of your real code?Baxley
@Dave Sherohman, Good advice in general, but the problem was explained and a solution was presented two hours before your comment. You can replicate the problem by preceding the OP's code with: $y='y'; $this->{'libraries'}->{$y}->{'cellHash'} = bless({});. Note that you must use 5.14 or higher to get the error the OP got.Vanadium
V
10

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} })) { ... }
Vanadium answered 13/6, 2013 at 6:7 Comment(0)
K
-1

%{$this->{'libraries'}->{$y}->{'cellHash'}} .I missed the flower bracket and the % .

Kinser answered 13/6, 2013 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.