I have a fairly perplexing problem with accessing a value in a 2d
hashref. Even though
Data::Dumper shows that
$self->{established}->{intro_rec} does exist within the
hashref, attempt to access this value fail, as indicated by the two
warnings (Use of uninitialized value in sprintf at
blib/lib/AI/Proplog.pm line 70.) as well as by the fact that the
output of the sprintf is empty.
However, this is perplexing because the Data::Dumper output
on the
same line shows these values as existing.
There is one peculiar thing about the particular element I want to
access. It was added during the second time I added things to this
element of the hashref. However, a similar sample program (where I add
a set of elements, then later add another set of elements) worked fine.
Source code
sub satisfied {
my ($self, @body) = @_;
if ($debug) {
warn sprintf "TESTING @body in satisfied() with self-e: %s",
Data::Dumper::Dumper($self->{established});
}
for my $prop (@body) {
if ($debug) {
warn sprintf "prop($prop): %s dr: %s dr2: %s dump: %s",
$prop,
$self->{established}->{$prop},
$self->{established}->{intro_rec},
Data::Dumper::Dumper($self->{established});
}
Debug output
TESTING intro_rec comp_org adv_prog theory in satisfied() with self-e:
+ $VAR1 = \
{
'adv_prog' => '1',
'intro_cs' => '1',
'theory' => '1',
'comp_org' => '1',
'intro_req' => '1'
};
Use of uninitialized value in sprintf at blib/lib/AI/Proplog.pm line 7
+0.
Use of uninitialized value in sprintf at blib/lib/AI/Proplog.pm line 7
+0.
prop(intro_rec): intro_rec dr: dr2: dump: $VAR1 = {
'adv_prog' => '1',
'intro_cs' => '1',
'theory' => '1',
'comp_org' => '1',
'intro_req' => '1'
};
Attempt to reproduce the problem in simpler circumstances (works
fine unfortunately)
package X;
use strict;
sub printlist {
my ($self, @L) = @_;
for my $prop (@L) {
if ($self->{established}->{$prop}) {
warn "$prop established";
} else {
warn "$prop NOT established";
}
}
}
my $self = {} ;
bless $self, 'X';
my @L = qw(intro_cs comp_org adv_prog theory);
my @M = qw(intro_req);
$self->{established}->{$_}++ for @L;
$self->printlist(@L);
$self->{established}->{$_}++ for @M;
$self->printlist(@M);