Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I wrote the code quite a few years ago and now I'm thinking there's GOT to be a better way to do this. Here's a sample of my script finding the next available image
I want to know if there's a way to determine what index a certain number is, inside my hash. Now I know indexes are used with arrays, but is there a similar way to do this in hashes if the keys are numbers?# determine next eligible image my $next_cnt = 0; while ($lowest) { $next_cnt++; if (exists $upload{$next_cnt}) { last; } } $next_cnt = $next_cnt + 2; # jump one ahead
Ie:
We are on image 5 and want to find out what the previous and next number in sequence would be..1,2,3,5,9,10
There just has to be a way to automatically determine, in a sorted hash, what the previous and next items would be. Right?my $prev = $db{$picid}..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to check which index $x is in an hash
by GrandFather (Saint) on May 21, 2007 at 21:40 UTC | |
by johngg (Canon) on May 21, 2007 at 22:13 UTC | |
by GrandFather (Saint) on May 21, 2007 at 22:19 UTC | |
|
Re: how to check which index $x is in an hash
by shmem (Chancellor) on May 21, 2007 at 21:31 UTC | |
by Anonymous Monk on May 21, 2007 at 21:50 UTC | |
by shmem (Chancellor) on May 22, 2007 at 05:16 UTC | |
|
Re: how to check which index $x is in an hash
by Tux (Canon) on May 21, 2007 at 21:31 UTC | |
|
Re: how to check which index $x is in an hash
by Anonymous Monk on May 21, 2007 at 21:28 UTC |