On 28 February 2016 at 21:59, rakesh sharma <rakeshsharm...@hotmail.com> wrote:
> According to docs bless returns the reference to self.


That just means that if you do:

my $x = {};
my $y = bless $x, "THING";

$y and $x will both be the same thing, a {} blessed into "Thing"

Its just more convenient to utilize the second of these because its simpler:

sub new {
    ...
    my $x = {};
    bless $x, $class;
    return $x;
}

^ works, but its just ugly when you can do

sub new {
    ...
    return bless {}, $class;
}



-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to