I understand one uses the ‘bless’ keyword in Perl inside a class’s ‘new’ method:
sub new { my $self = bless { }; return $self; }
But what exactly is ‘bless’ doing to that hash reference ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general,
blessassociates an object with a class.Now when you invoke a method on
$object, Perl know which package to search for the method.If the second argument is omitted, as in your example, the current package/class is used.
For the sake of clarity, your example might be written as follows:
EDIT: See kixx‘s good answer for a little more detail.