ivanovic3001 has asked for the wisdom of the Perl Monks concerning the following question:
I need some serious help. Been trying to figure out inheritance. Was given an assignment to practice inheritance. the code given was.
use v5.10.0; use warnings; use strict; package Animal; sub new { my $class = $_[0]; my $self = {text => "I am an abstract animal.\n"}; return bless($self, $class); } sub speak { my $self = shift; print $self->{"text"} } package Duck; our @ISA = qw(Animal); # qw(Animal) je ekvavilentno ("Animal") sub new { return bless({text => "I am a a duck.\n"}, shift); }
So this is the given code and I'm just supposed to make another package named Cow, Horse, etc. However reading online this is different from the stuff I had and the code doesn't print out anything when running and testing it. From what I gathered it's supposed to print "I am a duck" but it does nothing at all.
I apologize in advance if this is a newbie question but i really can't figure it out tried asking my peers but no one new anything. Thanks in advance for any help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl inheritance
by 2teez (Vicar) on Apr 18, 2014 at 18:45 UTC | |
by ivanovic3001 (Initiate) on Apr 18, 2014 at 20:57 UTC | |
by locked_user sundialsvc4 (Abbot) on Apr 18, 2014 at 21:44 UTC | |
by AnomalousMonk (Archbishop) on Apr 18, 2014 at 22:43 UTC | |
|
Re: Perl inheritance
by vinoth.ree (Monsignor) on Apr 18, 2014 at 18:44 UTC | |
|
Re: Perl inheritance
by bigj (Monk) on Apr 18, 2014 at 18:43 UTC | |
by AnomalousMonk (Archbishop) on Apr 18, 2014 at 22:38 UTC | |
by Anonymous Monk on Apr 18, 2014 at 23:25 UTC | |
|
Re: Perl inheritance
by Anonymous Monk on Apr 18, 2014 at 18:44 UTC |