Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 rifling through the Monastery: (5)
As of 2014-12-22 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls