G
Gerry Grieve
I have some data (course Info) which I'm trying to model as an
Object "panda_course" which stores the data into a hash. Besides other things,
a "panda_course" can have one or more "sections" which are modelled as another
Object & the references are stored in an array @ { $panda_course->{sections}.
This part works;
Each section can include one or more "Meetings" which is again an object which uses
an hash to store the info. I wanted to store references to these "meetings" objects
as an array in a "section->{meetings} (the meeting method is below.)
I expected each section to have a unique array of meeting references, but
I get only one array being used.
My test case is 1 course w 3 sections each having 1 meeting.
Below is some debug statements that the meeting method prints out:
Each panda_course_section is an unique hash, but each meeting array
is the same.
what I am missing, (besides a clue !!)
Gve
debug Output
panda_course:section:meeting Put panda_course_meeting=HASH(0xe2d40) on array self{meetings}
panda_course:section:meeting The array ref is $self{meetings} is ARRAY(0xdc7bc)
panda_course:section:meeting The self is panda_course_section=HASH(0x6a25c)
panda_course:section:meeting Put panda_course_meeting=HASH(0xe2ee4) on array self{meetings}
panda_course:section:meeting The array ref is $self{meetings} is ARRAY(0xdc7bc)
panda_course:section:meeting The self is panda_course_section=HASH(0xe4c98)
panda_course:section:meeting Put panda_course_meeting=HASH(0xe2f5c) on array self{meetings}
panda_course:section:meeting The array ref is $self{meetings} is ARRAY(0xdc7bc)
panda_course:section:meeting The self is panda_course_section=HASH(0xe4e3c)
End_of_debug Output
sub meeting
{
my $self = shift;
my $type = ref($self) || die "<<$self>> is not an object\n";
my $rest = shift;
my $m = panda_course_meeting->new();
while ($rest =~ m[<(\w+?)>(.*?)</\1>]msg)
{
next unless ($1);
my $field = $1;
my $value = $2;
$value =~ s/^\s*$//;
$m->$field($value);
}
print "panda_course:section:meeting Put $m on array self{meetings} \n";
print "panda_course:section:meeting The array ref is \$self{meetings} is $self->{meetings} \n";
print "panda_course:section:meeting The self is $self \n\n";
push @ { $self->{meetings} }, $m;
return $self->{meetings};
}
Object "panda_course" which stores the data into a hash. Besides other things,
a "panda_course" can have one or more "sections" which are modelled as another
Object & the references are stored in an array @ { $panda_course->{sections}.
This part works;
Each section can include one or more "Meetings" which is again an object which uses
an hash to store the info. I wanted to store references to these "meetings" objects
as an array in a "section->{meetings} (the meeting method is below.)
I expected each section to have a unique array of meeting references, but
I get only one array being used.
My test case is 1 course w 3 sections each having 1 meeting.
Below is some debug statements that the meeting method prints out:
Each panda_course_section is an unique hash, but each meeting array
is the same.
what I am missing, (besides a clue !!)
Gve
debug Output
panda_course:section:meeting Put panda_course_meeting=HASH(0xe2d40) on array self{meetings}
panda_course:section:meeting The array ref is $self{meetings} is ARRAY(0xdc7bc)
panda_course:section:meeting The self is panda_course_section=HASH(0x6a25c)
panda_course:section:meeting Put panda_course_meeting=HASH(0xe2ee4) on array self{meetings}
panda_course:section:meeting The array ref is $self{meetings} is ARRAY(0xdc7bc)
panda_course:section:meeting The self is panda_course_section=HASH(0xe4c98)
panda_course:section:meeting Put panda_course_meeting=HASH(0xe2f5c) on array self{meetings}
panda_course:section:meeting The array ref is $self{meetings} is ARRAY(0xdc7bc)
panda_course:section:meeting The self is panda_course_section=HASH(0xe4e3c)
End_of_debug Output
sub meeting
{
my $self = shift;
my $type = ref($self) || die "<<$self>> is not an object\n";
my $rest = shift;
my $m = panda_course_meeting->new();
while ($rest =~ m[<(\w+?)>(.*?)</\1>]msg)
{
next unless ($1);
my $field = $1;
my $value = $2;
$value =~ s/^\s*$//;
$m->$field($value);
}
print "panda_course:section:meeting Put $m on array self{meetings} \n";
print "panda_course:section:meeting The array ref is \$self{meetings} is $self->{meetings} \n";
print "panda_course:section:meeting The self is $self \n\n";
push @ { $self->{meetings} }, $m;
return $self->{meetings};
}