in reply to Determing the indice of an array

It would seem that you already have your answer, but it's worth pointing out that there is one fundemental problem with using a hash to related values in an array with its indices: It fails if you can have duplicate values.

Given that you need to create the hash to do it, it makes me question if an array is the right structure for your purpose in the first place.

As you don't give any details of why you want to extablish the index from the value, or what significance that index will have in your program, we cannot speculate on what might be a better approach to the problem, but a voice in the back of my head tells me that given this information, there is a better way.

Then again, there is another voice in my head telling me that this is a good time to be buying stocks and shares, but I'm studiously ignoring that one.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.