|laziness, impatience, and hubris|
Re: HASH Array adviceby serf (Chaplain)
|on Jan 24, 2006 at 11:46 UTC||Need Help??|
There's no specific reason not to.
If you are only making a small hash (with low numbers) you may find that an array is easier and more efficient *but* there are benefits in using a hash this way over using an array:
Particularly if you have to use a very large index number in the array; I believe that an array is created with (empty where not defined) elements up to the size of the highest index number, so by using a large index number you are pre-allocating (and therefore wasting) a chunk of un-needed memory.
On the other hand with an array you can just do:
and get all the elements back in order (which may or may not be useful in the case you are looking at), whereas with a hash you would have to sort the keys:
or explicitly ask for them:
(which obviously means using a hash *and* an array!) because a hash does not store the keys (or values) in numerical order.