Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: why use a hash instead of an array

by LanX (Canon)
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.

HTH

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-07-10 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (215 votes), past polls