So looking at the following package:
{ package Horse;
           @ISA = qw(Animal);
           sub sound { "neigh" }
           sub name {
             my $self = shift;
             $$self;
           }
           sub named {
             my $class = shift;
             my $name = shift;
             bless \$name, $class;
           }
         }

followed by the following instantiation lines:

my $talking = Horse->named("Mr. Ed");
print $talking->name, " says ", $talking->sound, "\n";

The only variable I see passed to the package is the name "Mr. Ed" which is in fact 
passed to the constructor "named" located in the package "Horse". Is this correct? 
So the constructor "named" takes the following list:

@_ = {Horse, "Mr. Ed"}

Is this correct? If so then "Horse" would be put into the scalar $class, and "Mr. Ed" 
would be put into the scalar $name. Is this correct? Ok so is $talking now an 
instance? And how does the "$talking->sound" produce "neigh"? Is the "@ISA" line and 
the sub name function needed in this package for Horse to still work, or is that there 
for inheritance purposes only?

Thanks.
SA

P.S. I kind of try to work my questions out as I go along so sorry for the details if 
it is too much.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to