in reply to [Resolved]Perl inheritance

My first guess would be, that you give bless the parameters in wrong order: So in package Duck,
sub new { # shift means shift @_ and will have $_[0] inside # what means $self like in package Animal return bless(shift, {text => "I am a a duck.\n"}); # and the class name needs to be first parameter }

So, you accidently blessed the class 'I am a duck.\n' instead of the class Duck :-) But as 'I am a duck.\n'-class also @ISA Animal, it still could speak and speaks there $self->{text} that had never been defined anywhere, so it prints nothing at all absolutely correctly :D

Greetings,
Janek Schleicher

Replies are listed 'Best First'.
Re^2: Perl inheritance
by AnomalousMonk (Archbishop) on Apr 18, 2014 at 22:38 UTC

    The order of arguments to bless in the OP is correct.

    BTW: My favorite "off-label" use of the  => (fat comma) operator (see perlop) is in a statement like
        return bless $object_ref => $class;
    which can be read "return the result of blessing object reference into class".