I still don't quite understand why 'four' is being repeated.
Abigail-II actually answered this question for you:
Third, it's showing four twice because you never delete the highest number when re-assigning the numbers.
I hate to push the issue, but even with your further description, an array sounds like a more appropriate (and less error-prone) data-structure for this problem. Matter of fact you wouldn't even have this problem at all if you used a tied-array for this. It seems to me that your index-keys aren't even really nessecary at all, they are just indecies to the natural order of your list.

With an array, your HTML-display code could just use a "counter" variable for your page number display rather than the hash-key. Something like this.

foreach my $page_num (1 .. scalar @pages) { print "<A HREF='script.pl?page=$page_num'>page $page_num</A>"; }
Then your CGI code would just use the value of "page" as an index to your array, and it will always be guarenteed to be there (assuming they don't reach over the bounds of your array in some way, but thats another problem).

If this weren't a tied hash i might recommend re-building it from a totally empty (new) hash then you wouldn't need to deal with this problem at all, but i assume the performance penalty on that would be painful.

-stvn

In reply to Re: Re: Re: rebuilding hashes by stvn
in thread rebuilding hashes by coldfingertips

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.