Type of argument to keys on reference must be unblessed

4k views Asked by At

I am very new to perl and I have been given the task of maintaining a webpage. I have found a bug that I do not know how to fix.

The perl script stops on the following code.

my @failedTests = (sort(keys ($TestResultsData{$currPlatform}{$currDate}{failedtests})));
while ( @failedTests )
{
 ...

The error message is:

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

Can that line of code be re-written so that it works?

1

There are 1 answers

3
tobyink On BEST ANSWER

The value of $TestResultsData{$currPlatform}{$currDate}{failedtests} is a blessed hashref. keys cowardly refuses to operate on blessed hashrefs because it would break the illusion of encapsulation and overloading.

(Older versions of Perl wouldn't accept a hashref at all - you needed to pass it a proper hash.)

Try manually dereferencing the hashref into a hash using:

my @failedtests = sort keys %{ $TestResultsData{$currPlatform}{$currDate}{failedtests} };