in reply to Perl OO Help: Urgent :)

$obj->get_value calls $self->{lib}->get_value and that was populated with $lib->get_list in list context, so it's calling get_value on the first object returned by get_list.
($self->{lib}) = ($lib->get_list("library")); # this is a lot like my @list = $lib->get_list("library"); my ($var) = @list; # only it's storing it in {lib} # and $self->{lib}->get_value # is then rather like $var->get_value # which is rather like $list[0]->get_value

-Paul

Replies are listed 'Best First'.
Re^2: Perl OO Help: Urgent :)
by Anonymous Monk on Jul 31, 2009 at 04:06 UTC
    Hi Paul, Sorry, new to Perl so need some more clarification. In my code, I have the line (please see the code in my question/request)

     ($self->{lib})  = ($lib->get_list("library"));

    what does ($self->{lib}) contain? Thanks, Mala

      After that statement, $self->{lib} contains the first element of the list returned by $lib->get_list('library'). Without knowing what that method returns, no one can be more specific.

        Hi Chromatic and other Monks :)
        Here is the code for the class and the class method that  $lib->get_list("library") will be calling:
        package Kprocess::Container; sub new { my $class = shift; my $self = { line => shift, items => undef, close => undef, }; $self->{line} = "" unless $self->{line}; bless $self, $class; } sub get_list { my ($self, @keywords) = @_; my $items = $self->{items}; my @list = (); return @list unless $items; foreach my $item (@{$items}) { push @list, $item if ($item->is(@keywords)); } return @list; }

        Combined with this above piece of code and the code in the original question I asked, can you please let me know what  ($self->{lib}) will contain from the line   ($self->{lib}) = ($lib->get_list("library")); in the question asked?
        Appreciate all the help.
        Hi Chromatic and other Monks :)

        Here is the code for the class and the class method that $lib->get_list("library") will be calling:

        package Kprocess::Container; sub new { my $class = shift; my $self = { line => shift, items => undef, close => undef, }; $self->{line} = "" unless $self->{line}; bless $self, $class; } sub get_list { my ($self, @keywords) = @_; my $items = $self->{items}; my @list = (); return @list unless $items; foreach my $item (@{$items}) { push @list, $item if ($item->is(@keywords)); } return @list; }


        Combined with this above piece of code and the code in the original question I asked, can you please let me know what  ($self->{lib}) will contain from the line  ($self->{lib}) = ($lib->get_list("library")); in the question asked?

        Appreciate all the help.

        --Mala