in reply to OOP method usage

I get "foo" and I want to get "bar". What am I doing wrong?

You're not calling _sub1 as a method. Try  sub2 { shift()->_sub1; }

Replies are listed 'Best First'.
Re^2: OOP method usage
by Anonymous Monk on Jul 07, 2012 at 09:32 UTC
    Thank you for your reply. That works like a charm. Am I able to use $self->_sub1; in a constructor? Or is it bad programming practice ? Example:
    sub new { my $class = shift; my $self = { _txt => shift }; bless $self, $class; $self->_sub1(); return $self; }

      Yes, you can call an instance method on $self in the constructor, provided you have first called bless on it (as in your example).

      is it bad programming practice ?

      No, it’s standard practice. See perlobj:

      Once we've blessed the hash referred to by $self we can start calling methods on it. This is useful if you want to put object initialization in its own separate method:

      sub new { my $class = shift; my $self = {}; bless $self, $class; $self->_initialize(); return $self; }

      HTH, and welcome to the Monastery!

      Athanasius <°(((><contra mundum