|We don't bite newbies here... much|
Re: why use a hash instead of an arrayby Preceptor (Deacon)
|on Jun 11, 2013 at 19:08 UTC||Need Help??|
So you've set up a bunch of variables, that act as references to elements of an array? You could do that, but ... what advantage do you gain by doing so?
I really wouldn't worry about efficiency - algorithm design is far more relevant than use of arrays vs. hashes.
Otherwise? Well, hashes are just a much simpler idiom to use - clearer code is more valuable than squeezing out miniscule performance advantages.
A lot of data _is_ structured as key/value pairs, and being able to manipulate it trivially is an advantage.
For example - given a list of words (one perl line for simplicity) count occurences.
With a hash:
You don't need to completely swap hashes for lists, but personally I'd suggest that any time you're using array indicies, you're probably doing something wrong, and making your code less readable.
Is a very useful idiom.