Composite Class Help - Can't access object's member data (hash of arrays)

B

Brett.R.Davis

I need help please!

I cannot figure out what I am doing wrong while trying to access an
object's member data - a hash of arrays whose elements are objects of
another class.

The realtionship is:

LMI::Class::Register - has a - LMI::Class::Field stored in a hash of
arrays :

Declared in the LMI::Class:Register like

$self->{FIELDS} = {};

I get the following error messages when trying to access the objects
contained in the FIELD hash of arrays:

Pseudo-hashes are deprecated at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.
Use of uninitialized value in hash element at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.
Bad index while coercing array into hash at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.


FIELDS contains a hash of arrays containing Field Objects (defined
after this method)

# begin code
sub write_field {
my $self = shift;
my $field = shift;
my $symbolic = shift;
my $special;

if (exists $self->{FIELDS}{$field}) {
foreach my $f_obj (@{$self->{FIELDS}{$field}}) {
if (defined $f_obj->{SPECIALS}) {
#Line 168
foreach $special ($f_obj->specials()) {
if (exists $self->{F_TABLE}{$special}) {
$f_obj->data($symbolic);
$self->{DATA} = $self->{DATA} |
$f_obj->get_vector($self->{SIZE});
return 1;
}
}
}
else {
$f_obj->data($symbolic);
$self->{DATA} = $self->{DATA} |
$f_obj->get_vector($self->{SIZE});
return 1;
}
}
}
return 0;

}

When I run Data::Dumper on $f_obj I get:

$VAR1 = [
bless( {
'SIZE' => 4,
'SPECIALS' => undef,
'NAME' => 'VER',
'DESCRIPTION' => 'This field defines the version of
the DID1 register format',
'VECTOR' => undef,
'DATA' => '0',
'MASK' => 4026531840,
'SYMBOLS' => {
'Fury_ib' => '1',
'Stellaris_ib' => '0'
}
}, 'LMI::Class::Field' )
];

When I run Data::Dumper on the container object (contains above object)

$VAR1 = bless( {
'SIZE' => 32,
'SPECIALS' => [
undef,
undef
],
'NAME' => 'DID1',
'ADDR_OFFSET' => 4,
'F_TABLE' => {},
'FLAGS' => undef,
'IBADDR' => 0,
'DESCRIPTION' => 'Device Identification 1',
'DATA' => 0,
'MASK' => 0,
'FIELDS' => {
'VER' => [
[
bless( {
'SIZE' => 4,
'SPECIALS' => undef,
'NAME' => 'VER',
'DESCRIPTION' =>
'This field defines the...',
'VECTOR' => undef,
'DATA' => '0',
'MASK' =>
4026531840,
'SYMBOLS' => {

'Fury_ib' => '1',

'Stellaris_ib' => '0'
}
}, 'LMI::Class::Field'
)
]
]
}
}, 'LMI::Class::Register' );




----------this is the class field constructor------
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{DESCRIPTION} = undef;
$self->{MASK} = undef;
$self->{SIZE} = undef;
$self->{DATA} = undef;
$self->{VECTOR} = undef;
$self->{SYMBOLS} = undef;
$self->{SPECIALS} = undef;
bless($self, $class); # but see below
return $self;
}

------------------this is the class register
constructor---------------------
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{NAME} = undef;
$self->{DESCRIPTION} = undef;
$self->{ADDR_OFFSET} = 0;
$self->{IBADDR} = 0;
$self->{SIZE} = 32;
$self->{DATA} = 0;
$self->{MASK} = 0;
$self->{FIELDS} = {};
$self->{SPECIALS} = undef;
$self->{F_TABLE} = {};
$self->{FLAGS} = undef;
bless($self, $class);
return $self;
}
 
M

Mumia W.

[...]
I get the following error messages when trying to access the objects
contained in the FIELD hash of arrays:

Pseudo-hashes are deprecated at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.
Use of uninitialized value in hash element at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.
Bad index while coercing array into hash at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.


FIELDS contains a hash of arrays containing Field Objects (defined
after this method)

# begin code
sub write_field {
my $self = shift;
my $field = shift;
my $symbolic = shift;
my $special;

if (exists $self->{FIELDS}{$field}) {
foreach my $f_obj (@{$self->{FIELDS}{$field}}) {
if (defined $f_obj->{SPECIALS}) {
#Line 168

According to the output from Data::Dumper below, $f_obj is an
array reference, not a hash reference, so $f_obj->{SPECIALS}
is invalid.

foreach $special ($f_obj->specials()) {
if (exists $self->{F_TABLE}{$special}) {
$f_obj->data($symbolic);
$self->{DATA} = $self->{DATA} |
$f_obj->get_vector($self->{SIZE});
return 1;
}
}
}
else {
$f_obj->data($symbolic);
$self->{DATA} = $self->{DATA} |
$f_obj->get_vector($self->{SIZE});
return 1;
}
}
}
return 0;

}

When I run Data::Dumper on $f_obj I get:

$VAR1 = [
bless( {
'SIZE' => 4,
'SPECIALS' => undef,
'NAME' => 'VER',
'DESCRIPTION' => 'This field defines the version of
the DID1 register format',
'VECTOR' => undef,
'DATA' => '0',
'MASK' => 4026531840,
'SYMBOLS' => {
'Fury_ib' => '1',
'Stellaris_ib' => '0'
}
}, 'LMI::Class::Field' )
];

When I run Data::Dumper on the container object (contains above object)

$VAR1 = bless( {
'SIZE' => 32,
'SPECIALS' => [
undef,
undef
],
'NAME' => 'DID1',
'ADDR_OFFSET' => 4,
'F_TABLE' => {},
'FLAGS' => undef,
'IBADDR' => 0,
'DESCRIPTION' => 'Device Identification 1',
'DATA' => 0,
'MASK' => 0,
'FIELDS' => {
'VER' => [
[
bless( {
'SIZE' => 4,
'SPECIALS' => undef,
'NAME' => 'VER',
'DESCRIPTION' =>
'This field defines the...',
'VECTOR' => undef,
'DATA' => '0',
'MASK' =>
4026531840,
'SYMBOLS' => {

'Fury_ib' => '1',

'Stellaris_ib' => '0'
}
}, 'LMI::Class::Field'
)
]
]
}
}, 'LMI::Class::Register' );

[...]

Your program is not complete and runnable by others, and it's
too long; I can't help you beyond the above.
 
L

Leah.M.Davis

thank you - i will try to boil it down to a specific case.

[...]
I get the following error messages when trying to access the objects
contained in the FIELD hash of arrays:

Pseudo-hashes are deprecated at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.
Use of uninitialized value in hash element at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.
Bad index while coercing array into hash at
/home/bdavis/usr/local/lib/lib/perl5/site_perl/5.8.5/LMI/Class/Register.pm
line 168.


FIELDS contains a hash of arrays containing Field Objects (defined
after this method)

# begin code
sub write_field {
my $self = shift;
my $field = shift;
my $symbolic = shift;
my $special;

if (exists $self->{FIELDS}{$field}) {
foreach my $f_obj (@{$self->{FIELDS}{$field}}) {
if (defined $f_obj->{SPECIALS}) {
#Line 168

According to the output from Data::Dumper below, $f_obj is an
array reference, not a hash reference, so $f_obj->{SPECIALS}
is invalid.

foreach $special ($f_obj->specials()) {
if (exists $self->{F_TABLE}{$special}) {
$f_obj->data($symbolic);
$self->{DATA} = $self->{DATA} |
$f_obj->get_vector($self->{SIZE});
return 1;
}
}
}
else {
$f_obj->data($symbolic);
$self->{DATA} = $self->{DATA} |
$f_obj->get_vector($self->{SIZE});
return 1;
}
}
}
return 0;

}

When I run Data::Dumper on $f_obj I get:

$VAR1 = [
bless( {
'SIZE' => 4,
'SPECIALS' => undef,
'NAME' => 'VER',
'DESCRIPTION' => 'This field defines the version of
the DID1 register format',
'VECTOR' => undef,
'DATA' => '0',
'MASK' => 4026531840,
'SYMBOLS' => {
'Fury_ib' => '1',
'Stellaris_ib' => '0'
}
}, 'LMI::Class::Field' )
];

When I run Data::Dumper on the container object (contains above object)

$VAR1 = bless( {
'SIZE' => 32,
'SPECIALS' => [
undef,
undef
],
'NAME' => 'DID1',
'ADDR_OFFSET' => 4,
'F_TABLE' => {},
'FLAGS' => undef,
'IBADDR' => 0,
'DESCRIPTION' => 'Device Identification 1',
'DATA' => 0,
'MASK' => 0,
'FIELDS' => {
'VER' => [
[
bless( {
'SIZE' => 4,
'SPECIALS' => undef,
'NAME' => 'VER',
'DESCRIPTION' =>
'This field defines the...',
'VECTOR' => undef,
'DATA' => '0',
'MASK' =>
4026531840,
'SYMBOLS' => {

'Fury_ib' => '1',

'Stellaris_ib' => '0'
}
}, 'LMI::Class::Field'
)
]
]
}
}, 'LMI::Class::Register' );

[...]

Your program is not complete and runnable by others, and it's
too long; I can't help you beyond the above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top