in reply to Re^2: How to detect a hash container key from a referenced sub value
in thread How to detect a hash container key from a referenced sub value
I couldn't understand the purpose of the bless function
Normally, if you have a hash reference:
my $hash = { a => 1, b => 2 };
you can write:
say $hash->{a};
but you cannot use a hash reference to call a function, e.g.
$hash->some_func()
If you look at the code that creates a class, the new() function creates a variable called $self and assigns it a reference to a hash. bless() makes it so that you can use the hash reference to call functions.
An object is different from any other data type in Perl in one and only one way: you may dereference it using not merely string or numeric subscripts with simple arrays and hashes...
$aref->[0]$href->{'a'}...but with named subroutine calls...
$href->some_func()In a word, with methods.
perltoot
|
|---|