Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am learning Perl and I am having a problem with simple packages. The problem is in my second package I can't call the package name of the previous package. Here is my code and also I am using the Perl Padre IDE. Can y'all show me what I am doing wrong when i run the package is shows that it is using the $name from the Cat package and not Dog
package Dog; our $name="Odie"; my $gender = "male"; @treats = ( "table scraps", "pork bone", "bacon twists", "rawhide" ); sub play{ my $dogname = shift; print "$dogname catches a tennis ball.\n"; } package Cat; $name = "Garfield"; print "Treats are : @treats \n"; print "$name says hello to $Dog::name. \n" ; print "$Dog::name is a $Dog::gender. \n" ; print "$name prefers chicken flavored Temptations\n" ; print "$Dog::name loves ",join (" , ", $Dog::treats) , " but prefers $Dog::treats[0]\n" ; Dog::play ($name);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Package problems
by shmem (Chancellor) on Apr 14, 2017 at 21:37 UTC | |
Re: Package problems
by kennethk (Abbot) on Apr 14, 2017 at 22:15 UTC | |
Re: Package problems
by Anonymous Monk on Apr 14, 2017 at 18:41 UTC | |
Re: Package problems
by Anonymous Monk on Apr 14, 2017 at 20:55 UTC | |
Re: Package problems
by Anonymous Monk on Apr 14, 2017 at 18:16 UTC |
Back to
Seekers of Perl Wisdom