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

No comments:

Post a Comment