|Just another Perl shrine|
Re^3: An irrational coding choice foundby BrowserUk (Pope)
|on Mar 21, 2012 at 16:54 UTC||Need Help??|
one nitpick (probably too obvious to mention ...
It's not so much "too obvious" as not really applicable to the OPs question.
I wasn't trying to define the absolute criteria for when to use an array or a hash.
Just clarify the reasoning for trading the habitual use of hashes for arrays where that is otherwise a practical proposition.
In order for that trade to even begin to be a practical proposition, the "natural keys" to the data have to be small, near contiguous integers; or otherwise be simply and quickly transformable into a range of small, near contiguous integers. If that is not the case, no such trade is possible and the OPs question is moot.
You can save time using a hash if you need to access a single element of a hash, instead of searching the array for your elements.
In order to use the lookup abilities of an associative array, you must start with the key and either:
For the very specific subset of cases where the array-instead-of-hash trade is possible, it would mean that you would be starting with an index into the array. And either looking to retrieve the value at that index; or test if there is any value at that index.
In both cases, if the initial trade is feasible then the lookup in the array will be substantially faster than lookup in the hash.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.