Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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.


Comment on Re: why use a hash instead of an array
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-09-22 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls