in reply to [Resolved]Perl inheritance
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 | |
by Anonymous Monk on Apr 18, 2014 at 23:25 UTC |