On 11-09-03 03:54 PM, 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
}

foreach my $w ( $config->get_widgets() )

foreach my $w ( @{ $config->get_widgets() } )
# get_widgets returns a ref to an array
# @{ $array_ref } deferences it


{
     #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";
}

my expected output is...

widget1
widget2
widget3

--
Ronald Weidner


--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

"Make something worthwhile."  -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to