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

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.

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

    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.

Re^5: Perl OO Help: Urgent :)
by SuicideJunkie (Vicar) on Jul 31, 2009 at 13:55 UTC
    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.