It's not clear to me that what you want is at all possible, without violating the "information hiding" strategy of the IxHash object. Looking at the docs for Tie::IxHash, it seems that the OO interface on this module does not provide any direct accessors to the actual storage for hash values -- it only provides methods that return lists of things (i.e. copies of values or keys), and methods that add, delete or rearrange elements in its internal (hidden) data structure. You have the FETCH( $key ) and STORE( $key ) methods, but again these are really just function calls, not direct access to scalar storage.

So the problem is that the "-textvariable" attribute on the Tk::Entry widget requires a reference to a scalar, but the OO design of IxHash does not provide the necessary access for doing this. You'd have to break the rules of OO, look into the IxHash code to see how the value is actually stored, and work out the syntax so that you pass a reference to that storage location when you configure the Entry widget. Very ugly and not a good idea.

(update: Just checked the Tk::Entry "textvariable" specs -- I've actually tried it with both "-textvariable => $scalar" and "-textvariable => \$scalar", and they both work; but trying to do it with an IxHash object makes no sense: I'm not supposed to know what the module's internal scalar values are actually called, so I can't pass their names to -textvariable. :end-of-update)

Now the question is: what is IxHash giving you that you don't get with the normal hash? If I understand its man page, it allows the elements of the hash to be retrieved in a fixed order -- in other words, it seems to be implementing something like an array where "name" attributes are associated with each array index.

If that's what you want, it might be easier to build that yourself, so that you have direct access to where the values are stored, and can assign references to that storage when setting up the "-textvariable" attribute of the Entry widget. One way to do this would be to use a HoH to hold both values and ordering sequence in a single data structure:

for $ord (0..5) { # set $key and $val for this iteration, and: $hash{$key}{value} = $val; $hash{$key}{order} = $ord; }
This way, you can still pass a reference to the value, and you can sort the hash elements by their established index order. Another way would be an AoA, to store name/value pairs in a fixed sequence:
for (0..5) { # set $key and $val for this iteration, and: push @array, [ $key, $val ]; } # equivalent to: $array[0][0] => $array[0][1]

In reply to Re: Tk Entry and IxHash by graff
in thread Tk Entry and IxHash by aplonis

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.