Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Blessing tied hash

by zwon (Monsignor)
on May 05, 2012 at 16:13 UTC ( #969056=note: print w/ replies, xml ) Need Help??


in reply to Re: Blessing tied hash
in thread Blessing tied hash

Though bless indeed requires a reference as argument it actually tells the thingy referenced by REF that it is now an object, so it blesses the thingy, and not the reference:

use 5.010; use strict; use warnings; my %hash; say ref \%hash; bless \%hash, "Whatever"; say ref \%hash; __END__ HASH Whatever

PS of course you can bless reference too:

use 5.010; use strict; use warnings; my %hash; my $ref = \%hash; bless $ref, 'Array'; bless \$ref, 'Whatever'; say ref \%hash; say ref \$ref; __END__ Array Whatever


Comment on Re^2: Blessing tied hash
Select or Download Code
Re^3: Blessing tied hash
by anazawa (Beadle) on May 06, 2012 at 07:24 UTC
    Thanks for your suggestion. Though I'm sure your code works so, not sure how to relate your code with what you mentioned. Does your code prove what you mentioned? 'thingy' sounds unclear for me :(
    Anyway, thanks :)

      thingy is what the reference points to, it may be hash, array, scalar, subroutine. What I'm saying, and what code demonstrates is that you can bless a hash, not just the reference as tobyink said.

        That makes sense. Although bless() requires a reference to the thingy, bless() makes the thingy blessed, not the reference itself. I didn't care this slight difference. In this context, to bless a tied hash, we pass the reference (to a tied hash) to bless().

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969056]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-10-01 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (41 votes), past polls