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.
|
|---|