in reply to Re: Perl OO Help: Urgent :)
in thread Perl OO Help: Urgent :)

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

Replies are listed 'Best First'.
Re^3: Perl OO Help: Urgent :)
by chromatic (Archbishop) on Jul 31, 2009 at 05:35 UTC

    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.

        As I said before, $self->{lib} will contain the first element of the list returned from $lib->get_list('library').

        The get_list() method apparently returns a list of items from $self->{items} for which $item->is('library') is true.

        If that's still not clear to you, I'm not sure what else to tell you.

        After that statement, $self->{lib} contains the first element of the list returned by $lib->get_list('library').

        vs
        sub get_list { ... push @list, $item if ($item->is(@keywords)); ... return @list; }

        You should definitely invest in a test.pl file. Then you can paste these things into it and Try It And See. Sprinkle lots of print statements so you can follow along the code path wherever it is not clear to you.


        The monks can fry your fish, and they can give you some tips and some bait, but you still need to wake up and climb onto the boat.
      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