in reply to Simple OO Question

That's not what I get:

>perl -w tmp.pl Use of uninitialized value in print at tmp.pl line 25. me

That is because in ->Show_Me, you're calling _Print_me while you should be calling ->_Print_Me instead:

sub Show_Me { my ($self) = @_; return $self->_Print_Me(); # <-- }

Replies are listed 'Best First'.
Re^2: Simple OO Question
by DStaal (Chaplain) on Sep 16, 2010 at 13:02 UTC

    As an expansion: _Print_Me() is expecting an argument (a reference to a hash), which it puts in $self. It then prints the hash element user out of that argument.

    In your version of Show_Me, you don't pass it that expected argument. There are two ways to do so in this case: Using standard function notation (_Print_Me($self)) or using object notation, which implies the object itself as the first argument. ($self->_Print_Me())

      As a further expansion: The difference between _Print_Me($self) and $self->_Print_Me is that _Print_Me($self) will always use the current package's _Print_Me, while $self->_Print_Me will find the appropriate _Print_Me for the package (class) that $self is blessed into.

      As a general rule, you'll want to use _Print_Me($self) when you want to use one specific implementation, no matter what, and use $self->_Print_Me when you want to allow for polymorphism (which should be almost always, since you never know when $self might belong to a subclass which has overridden _Print_Me).