I think davidj is onto something there, but his version of your code won't work any better than your original, because there are too many other mistakes that he didn't try to fix.

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 );

In reply to Re: Hash of Arrays using Perl::Tk by graff
in thread Hash of Arrays using Perl::Tk by Raad

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.