Re: bless function

2001-09-17 Thread baby lakshmi


Hello Jeff,
Thank you for ur reply.

 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.


should we have to use the bless fuction in the constructor alone we can 
use the created object ($foo) to invoke the function. isnt it??? so whatz 
the real advandage of using bless function??? and why we need to bless that 
particular object to some specific classes...
I really dont understand the functionality and advantages of using bless.

Thank you
Regards
Babylakshmi


_
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


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




Re: bless function

2001-09-17 Thread Jeff 'japhy/Marillion' Pinyan

On Sep 17, baby lakshmi said:

should we have to use the bless fuction in the constructor alone we can 
use the created object ($foo) to invoke the function. isnt it??? so whatz 
the real advandage of using bless function??? and why we need to bless that 
particular object to some specific classes...

The bless() function creates an object.  That is what it does.  Without
it, you can't have an object in the general sense of the word.  Using
bless() takes a reference, and makes it an object of a specific
class.  Then, that object can use the methods of the class it belongs to.

I suggest you read a Perl OO tutorial, such as perldoc perlboot.

-- 
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]




Re: bless function

2001-09-17 Thread _brian_d_foy

In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] (Baby Lakshmi) wrote:

 I really dont understand the functionality and advantages of using bless.

bless() tags a reference with a package name, effectively turning
it into an object.  without bless you don't have objects.

http://www.perldoc.com/perl5.6.1/pod/func/bless.html
-- 
brian d foy [EMAIL PROTECTED] - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html

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




bless function

2001-09-14 Thread baby lakshmi

hello friends,
i have a doubt in the concept of blessing.

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;
}

my $talking = Animal-named(xyz);
$talking -eat(hay);
#
#

In this program i dont understand what is the function of bless??? and where 
xyz is stored.

May be the concept of bless function is not clear to me. can u please 
expliain me in detail abt this funtion which will be definitely helpful to 
me.

thank you
Regards
Babylakshmi


_
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


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




Re: bless function

2001-09-14 Thread Jeff 'japhy/Marillion' Pinyan

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]