in reply to Tk Entry and IxHash
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:
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 $ord (0..5) { # set $key and $val for this iteration, and: $hash{$key}{value} = $val; $hash{$key}{order} = $ord; }
for (0..5) { # set $key and $val for this iteration, and: push @array, [ $key, $val ]; } # equivalent to: $array[0][0] => $array[0][1]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Tk Entry and IxHash
by aplonis (Pilgrim) on Apr 14, 2004 at 01:19 UTC |