But isn't this already as simple as you could get? Here's the code I've played with:
use Data::Dumper; my $bhash = bless { key1 => 'val1', key2 => 'val2' }, 'FOO'; my %uhash = %$bhash; print Dumper($bhash); print Dumper(\%uhash); print "done\n";
And the output is:
$VAR1 = bless( { 'key1' => 'val1', 'key2' => 'val2' }, 'FOO' ); $VAR1 = { 'key1' => 'val1', 'key2' => 'val2' }; done
The bless() is used to associate the object a reference points to with a package that defines the object class. I am frankly not aware of any operator in Perl for 'curse' or 'unbless'.

Update: mp when you use the bless() operator on a hashref like so:
my %ahash = ( key1 => 1, key2 => 2 ); bless \%ahash, 'FOO';
You end up 'labeling' or 'associating' the %ahash structure with the package 'FOO'. Here's the code to prove this:
use Devel::Peek 'Dump'; use Data::Dumper; my %ahash = ( key1 => 'val1', key2 => 'val2' ); print "ORIGINAL HASH:\n"; print Dumper(\%ahash) ."\n"; print Dump(\%ahash) ."\n\n"; my $bhash = bless \%ahash, 'FOO'; print "ORIGINAL HASH (after blessing, note it's now been associated wi +th the 'FOO' package!!):\n"; print Dumper(\%ahash) ."\n"; print Dump(\%ahash) ."\n\n";
Which when you run it produces this output:
ORIGINAL HASH: $VAR1 = { 'key1' => 'val1', 'key2' => 'val2' }; SV = RV(0x3b828) at 0x2307c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x2dbc4 SV = PVHV(0x8ea80) at 0x2dbc4 REFCNT = 2 FLAGS = (PADBUSY,PADMY,SHAREKEYS) IV = 2 NV = 0 ARRAY = 0x25160 (0:6, 1:2) hash quality = 150.0% KEYS = 2 FILL = 2 MAX = 7 RITER = -1 EITER = 0x0 Elt "key1" HASH = 0x3e4d49 SV = PV(0x23444) at 0x2316c REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x952b8 "val1"\0 CUR = 4 LEN = 5 Elt "key2" HASH = 0x3e4d4a SV = PV(0x2342c) at 0x23250 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x952e8 "val2"\0 CUR = 4 LEN = 5 ORIGINAL HASH (after blessing, note it's now been associated with the +'FOO' package!!): $VAR1 = bless( { 'key1' => 'val1', 'key2' => 'val2' }, 'FOO' ); SV = RV(0x3b828) at 0x2307c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x2dbc4 SV = PVHV(0x8ea80) at 0x2dbc4 REFCNT = 3 FLAGS = (PADBUSY,PADMY,OBJECT,SHAREKEYS) IV = 2 NV = 0 STASH = 0x59b1c "FOO" ARRAY = 0x25160 (0:6, 1:2) hash quality = 150.0% KEYS = 2 FILL = 2 MAX = 7 RITER = -1 EITER = 0x0 Elt "key1" HASH = 0x3e4d49 SV = PV(0x23444) at 0x2316c REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x952b8 "val1"\0 CUR = 4 LEN = 5 Elt "key2" HASH = 0x3e4d4a SV = PV(0x2342c) at 0x23250 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x952e8 "val2"\0 CUR = 4 LEN = 5
Note that soon after the call to the 'bless' operator, the original hash structure was altered. There's now been a new 'STASH' field added to the hash RV structure. Again, as far as I know there's no means in current version of Perl to simply yank that field from the underlying hash structure. I'll play some more with this to see if there's a way of obtaining an unblessed structure without unnecessary copying however.

_____________________
# Under Construction

In reply to Re: How can I unbless an object? by vladb
in thread How can I unbless an object? by mp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.