On Sep 14, baby lakshmi said:
>package Animal;
>sub named {
> my $class = shift;
> my $name = shift;
> bless \$name, $class;
>}
>sub eat{
> my $class = shift;
> $class = ref($class) || $class;
> my $food = shift;
> print "$class eats $food\n";
>}
>In this program i dont understand what is the function of bless??? and where
>xyz is stored.
The bless() function takes a reference and a class, and says that the
reference "belongs" to that class. Specifically, this means that the
reference can access the methods of that class.
$foo = Animal->named("Jeff");
Now $foo is a reference (in your case, a scalar reference). If I were to
dereference it, I'd see the string "Jeff":
print $$foo; # Jeff
Since $foo is an Animal object, I can call any method in the Animal class
with $foo.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]