On 03/09/2011 20:54, Ron Weidner wrote:
In a module I have code that looks like this... sub add_widget { my $self = shift; my $new_widget = shift; push ( @{$self->{WIDGETS}}, $new_widget ); } sub get_widgets { my $self = shift; return $self->{WIDGETS}; } I'm writing a test that is failing at runtime with the following error. Can't call method "attrib" on unblessed reference at ./test.pl line 40. $config = new Widget(); my $i = 0; for ($i=0; $i<3; $i++) { my $w = new Widget(); $w->add_attrib("name", "widget".($i+1)); #add_attribute is tested and working $config->add_widget($w); #this is what I'm testing }
Hey Rod You have been working to implement a module that presents an OO interface, but you seem to have a poor grasp of Perl. I have told you what I thought was wrong with your add_widget method, but you seem to have implemented my fix without properly understanding what was wrong. We are not here to write and fix your code for you. It is time that you put up your hands to say that the task is beyond you.
foreach my $w ( $config->get_widgets() ) { #attrib is tested and working, but this foreach loop is not known to be valid code yet. print $w->attrib("name"); #<---- This is line 40. print "\n"; }
I suggest you think about what sort of value $config->get_widgets might be. Also, adding print statements to debug your code should help a lot. Cheers, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/