perldood has asked for the wisdom of the Perl Monks concerning the following question:
In file Animals.pm, I have package Cow; sub Cow::speak { my $class = shift; print "$class Cow goes moooo!\n"; } package Horse; sub Horse::speak { my $class = shift; print "$class Horse goes neigh!\n"; } package Sheep; sub Sheep::speak { my $class = shift; print "$class Sheep goes baaaah!\n"; } 1;
And calling script works like this. first code can print value of $class and second code doesnt, why ??
ThanksWorking code: #!/usr/bin/perl use lib '/home/perldood/Custom/perl/lib/perl5/Animals'; use Animals; Cow->speak; Horse->speak; Sheep->speak; Non working code: #!/usr/bin/perl use lib '/home/perldood/Custom/perl/lib/perl5/Animals'; use Animals; Cow::speak; Horse::speak; Sheep::speak; Can you please explain, Why ??
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $class name not pass in the new()
by chromatic (Archbishop) on Mar 12, 2012 at 07:01 UTC | |
by perldood (Initiate) on May 11, 2012 at 19:32 UTC | |
|
Re: $class name not pass in the new()
by Khen1950fx (Canon) on Mar 12, 2012 at 03:48 UTC | |
|
Re: $class name not pass in the new()
by NetWallah (Canon) on Mar 12, 2012 at 04:03 UTC |