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

Hello Monks,

I am unable to figure out the issue with my code.
I am passing an object to a subroutine - '_predecessors_complete' below, however, I get the following error in a certain case, marked below in the code with '--this line --' -

Can't use an undefined value as a HASH reference at Steps.pm line 264, <OEM2015FLAG> line 1.

The case occurs when I pass in a 'job' value that doesn't exist in the hash of all jobs. So, I tried checking if the job exists in the hash, using the 'if' exists' code.

Question is, which value exactly would be undefined for me to get this error message? I am printing $p here, and it is definitely defined.

OUTPUT -
p : JOBNAME1

Can't use an undefined value as a HASH reference at Steps.pm line 264, <OEM2015FLAG> line 1.

CODE -

my $rv = $self->_predecessors_complete( $self->predecessors ); ##$self +->predecessors is a reference to a hash sub _predecessors_complete { my ( $self, $predecessors ) = @_; while ( my $p = shift @{ $predecessors } ) { print "\np : $p\n"; --this line -- if ( ! exists $self->steps->{$p} ) { print "\nThe job $p has not been defined in the Scheduler!\n +"; return(100); } else {

Replies are listed 'Best First'.
Re: Unable to figure out - undefined value as a HASH reference
by SuicideJunkie (Vicar) on Jul 30, 2015 at 19:12 UTC

    What is $self->steps supposed to be? Whatever you intended, it is not a hash reference that you can look up $p in.

    Did you mean $self->{steps}{$p} perhaps?

      SuicideJunkie, that was it! I was not using the reference correctly. You saved me a few hours of breaking my head.

      Points!