ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:

This is the piece of code I am using.

if( any { /^\Q$req_type{$req_id}\E$/ } @req_reqest) { $OTAF_data{$req_type{$req_id}}++; $OTAF_hour_stats{$start_hour}{'Total_calls'}++; $OTAF_data{'Total'}{'Total'}++; if ($status eq "0") { $OTAF_data{'Failure'}{$req_type{$req_id}}++; $OTAF_data{'Errors'}{$db_error}++; $OTAF_data{'Total'}{'Success'}++; } elsif ($status eq "1") { $OTAF_data{'Success'}{$req_type{$req_id}}++; $OTAF_data{'Total'}{'Failure'}++; } }

Like this I am building a hash with all the information I needed. Later I want the error name which occured. For that I am using "keys"

my @occured_errors = keys $OTAF_data{'Errors'};

If there are no errors present on the day. Its showing an error  Type of argument to keys on reference must be unblessed hashref or arrayref at ./OTAF_Statistics_Report.pl line 184.

How to solve this problem???

Replies are listed 'Best First'.
Re: Check either keys are exists (keys on reference)
by Athanasius (Archbishop) on Jan 18, 2016 at 07:45 UTC

    Hello ravi45722,

    This line:

    my @occured_errors = keys $OTAF_data{'Errors'};

    should be giving you a keys on reference is experimental message. Change to the standard hash dereference syntax:

    my @occured_errors = keys %{ $OTAF_data{'Errors'} };

    and the error (i.e., the original problem) should go away, even when there is no Errors key present in the hash.

    Update: Added the underlined phrase for clarification.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,