Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: why use a hash instead of an array

by gurpreetsingh13 (Scribe)
on Jun 12, 2013 at 11:20 UTC ( #1038431=note: print w/replies, xml ) Need Help??

in reply to why use a hash instead of an array

A very very simple answer to your question. Please don't laugh.

If you have 5 sons, would you like to refer each one of them with name or with indices ?

You must have understood that internally hashes are just like arrays- somehow named arrays - whose values are referenced using keys. Arrays are better when a similar type of operation is performed on entire list. Hashes are better when you would like to use individual members of a group, which are always better to refer via a name which you can easily remember during coding and not via an index.

Just my 2 cents on that.

Replies are listed 'Best First'.
Re^2: why use a hash instead of an array
by DarrenSol (Acolyte) on Jun 13, 2013 at 15:10 UTC
    not fair. you tell me not to laugh then throw that one-liner at me...but actually i know a guy that does that. at least i think he's planning on doing that. mr rodriquez has one kid, a boy, that he calls hose-a. i guess he'll call his next son hose-b. ok, your turn, don't laugh.

      Extremely sorry if you felt wrong with that. But friend, it was just an example.

      Ok I am not laughing. But you will understand the importance of hashes once you start using the language to its full extent. Simpler code, shorter code, understandable code, easy to use etc. etc.

      Correct me if I am wrong. I believe perl was the first language to include hashes as first-class citizens. There must have been several selling points due to which all industry-standard languages like Java, C-Sharp, Python have now something similar to hash through API or jar or dll or dictionary

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038431]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-06-22 10:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.