in reply to Hash of Arrays using Perl::Tk
You say "everything works fine except..." but the code you posted doesn't actually compile -- you're using a bunch of variables that have not been declared with "my", including "@array", whose "$i'th" element (which is undefined) is being assigned as text for a Label widget, and $w (or @w in davidj's version), which is being assigned two different widgets; you "tie %hash" and then later declare "my %hash" (and assign values).
How about you post the code that actually runs? Also, look at the four blocks of 5 lines each, where the only difference from one block to the next is an array index. That's where a "for" loop comes in real handy -- saves a lot of repetitive typing (or copy/paste/editing)
If your database will be using actual key fields (rather than just numbers like 1..4) then keep using %hash -- but if you're just going to be handling records by means of a sequenctial record number, use an array-of-arrays.
Reconfiguring the "normal" and "disabled" states of the "Next" and "Last" buttons can be done a lot more simply -- e.g.:
my $nxtState = my $prvState = 'normal'; if ( $i == $first_index ) { $prvState = 'disabled'; } elsif ( $i == $last_index ) { $nxtState = 'disabled'; } $next->configure(-state => $nxtState ); $back->configure(-state => $prvState );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash of Arrays using Perl::Tk
by Raad (Acolyte) on Dec 01, 2004 at 14:22 UTC | |
|
Re^2: Hash of Arrays using Perl::Tk
by davidj (Priest) on Dec 01, 2004 at 08:33 UTC | |
by graff (Chancellor) on Dec 03, 2004 at 02:16 UTC |