PERL bless Function

Syntax

bless REF, CLASSNAME
bless REF

Definition and Usage

Tells the entity referenced by REF that it is now an object in the CLASSNAME package, or the current package if CLASSNAME is omitted. Use of the two-argument form of bless is recommended.

Return Value

  • The reference to an object blessed into CLASSNAME

Example

The object reference is created by blessing a reference to the package’s class. For example:
package Person;
sub new
{
my $class = shift;
my $self = {
_firstName => shift,
_lastName => shift,
_ssn => shift,
};
# Print all the values just for clarification.
print "First Name is $self->{_firstName}n";
print "Last Name is $self->{_lastName}n";
print "SSN is $self->{_ssn}n";
bless $self, $class;
return $self;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s