previous has asked for the wisdom of the Perl Monks concerning the following question:
{ package cParent; sub new { my $class = shift; my $self = {}; bless( $self, $class + ); #std line $self->{sub_passed_to_parent}=shift; $self->{test_att}=3; $self->{oChild}=cChild->new( $self, $self->{sub_passed_to_pare +nt} ); return $self; } } { package cChild; sub new { my $class = shift; my $self = {}; bless( $self, $class + ); #std line $self->{parent_obj_ref}=shift; $self->{sub_passed_to_child}=shift; print "in new for cChild and just calling sub_passed_to_child\ +n"; $self->{sub_passed_to_child}( $self->{parent_obj_ref} ); return $self; } } sub passed_sub { print "yes in passed_sub\n"; my $oParent_ref=shift; print "\$oParent_ref is $oParent_ref\n"; print "\$oParent_ref->{test_att} is $oParent_ref->{test_att}\n"; +#How do I access attribute {test_att} properly } print "going in\n"; my $oParent=cParent->new(\&passed_sub);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using passed parent object reference to get at attributes
by GrandFather (Saint) on Dec 20, 2015 at 00:34 UTC | |
by mr_ron (Deacon) on Dec 20, 2015 at 14:50 UTC | |
by previous (Sexton) on Dec 20, 2015 at 15:25 UTC | |
by previous (Sexton) on Dec 20, 2015 at 10:42 UTC | |
|
Re: using passed parent object reference to get at attributes
by NetWallah (Canon) on Dec 20, 2015 at 00:34 UTC | |
by previous (Sexton) on Dec 20, 2015 at 10:51 UTC |