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.
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).foreach my $page_num (1 .. scalar @pages) { print "<A HREF='script.pl?page=$page_num'>page $page_num</A>"; }
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.
-stvnIn reply to Re: Re: Re: rebuilding hashes
by stvn
in thread rebuilding hashes
by coldfingertips
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |