Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: why use a hash instead of an array

by LanX (Chancellor)
on Jun 12, 2013 at 12:03 UTC ( #1038450=note: print w/replies, xml ) Need Help??

in reply to why use a hash instead of an array

Your observations about similarities are true!

For instance in JavaScript arrays are (officially) implemented via hashes. =)

BUT there are certain differences in Perl.

  • arrays are ordered, hashes aren't
  • two indices with distance n mean the array has >n elements, the hash only >2
  • array lookup and memory consumption is far better for same number of elements
These differences in nature lead to different operators, something like push or shift doesn't make much sense for hashes without order. How do you find the highest index/key of an array?

And sometimes, e.g. when dealing with sparse matrices, arrays are simulated via hashes.


Cheers Rolf

( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038450]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2016-10-27 13:24 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (362 votes). Check out past polls.