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]
|