This is good. Thanks.

Maybe you can answer this one: The bug that started me down this path is something I mentioned having problems with before but in a different area. I can't tie elements of the tied hash. I think someone mentioned this as not possible. The reference issue came up in the course of tracking that down because when tying the reference, the tie works. I can only assume it's tying something I can no longer refer to. Test code using a hash-based scalar tie for the hash elements that upper cases them. Note that I also tried Tie::StdScalar with the same results (except that the tie did nothing).

package TieTest; sub TIESCALAR { return bless({}, __PACKAGE__) } sub STORE { @_[0]->{VALUE} = uc(@_[1]) } sub FETCH { @_[0]->{VALUE} } use strict; use Tie::IxHash; my $h = {}; my $a; tie %$h, "Tie::IxHash"; tie $h->{FOO}, "TieTest"; $h->{FOO} = 'foo'; tie $a, "TieTest"; $a = 'bar'; print "After scalar tie ...\n"; print "\$h->{FOO} = $h->{FOO}\n"; print "\$a = $a\n"; print "\$a tied? ", tied($a), "\n"; print "h->{FOO} tied? ", tied($h->{FOO}), "\n"; tie_ref(\$a); tie_ref(\$h->{FOO}); $a = 'bar2'; $h->{FOO} = 'foo2'; print "After reference tie ...\n"; print "\$h->{FOO} = $h->{FOO}\n"; print "\$a = $a\n"; print "\$a tied? ", tied($a), "\n"; print "h->{FOO} tied? ", tied($h->{FOO}), "\n"; sub tie_ref { my $ref = shift; my $tie; $tie = tie $$ref, "TieTest"; print "tie for reference $ref = $tie\n"; }
produces:
After scalar tie ... $h->{FOO} = foo $a = BAR $a tied? TieTest=HASH(0x13c8dc) h->{FOO} tied? tie for reference SCALAR(0x102efc) = TieTest=HASH(0x13c81c) tie for reference SCALAR(0x13c8d0) = TieTest=HASH(0x13c840) After reference tie ... $h->{FOO} = foo2 $a = BAR2 $a tied? TieTest=HASH(0x13c81c) h->{FOO} tied?

I love the abstraction ties offer but I find that all the nuances of using them are not well documented. Are there docs I'm missing that discuss ties in more detail?

The good news is that all this tracking helped me finally understand some inconsistent behavior. 8-)


In reply to Re: references to elements of tied hashes by steves
in thread references to elements of tied hashes by steves

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.