Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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)

Comment on Re: why use a hash instead of an array
Select or Download Code

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 exploiting the Monastery: (6)
As of 2015-11-30 06:53 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (762 votes), past polls