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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

If I had to choose between a language having arrays but no hashes, and a languages having hashes and no arrays, I would no doubt select the one with hashes (I have used at least a dozen other languages for serious purposes, and only one, besides Perl, namely Python, had hashes, at least natively, so I think I can claim that I know what it is to have hashes or not to have them). Just about everything that can be done with arrays can be done with hashes (if only by using the array subscripts as keys to the hash), but the reverse is really not true. Once you acquire a bit more experience with Perl or any other language having hashes (which sometimes have different names, they can be dictionnaries or associative arrays, or whatever), you will understand how immensely useful they are.

Just one example from my work, something which I am due to present in a Perl conference in Europe at the end of this week. I had a program written in a database exploration language that I will call G. G is a fine and rather fast language, but it does not have hashes (and, to me, it is by far its single most important defect). The program was running on a very large database and making very complex comparisons with a relatively large parameter file. The first time we ran it, we stopped it after a couple of days when we found that it was going to take about 180 days to complete. After some optimization work, I ended up with a predicted execution time of 60 days, and with no idea for further optimization. Of course, a 60-day running time was not acceptable (in the business context, 3 to 5 days would have been not ideal but still OK, but certainly not 60 days). I decided to completely rewrite the program in Perl using four simple hashes, two hashes of hashes and one hash of hashes of hashes. The program now runs in about one hour (about 1,400 shorter execution time). To make things clear, it is not by simply replacing the previous data structure by some hashes that I obtained this huge improvement, it is because hashes enabled me to use a completely different and far better algorithm.

Just one last thing, don't understand the above wrongly. My point is NOT that hashes are fast (they are fast, and this is important, but that is not my point). My point is that they very often allow for much better data structures and much better algorithms for many many tasks.

In reply to Re: why use a hash instead of an array by Laurent_R
in thread why use a hash instead of an array by DarrenSol

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2017-12-17 06:21 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (462 votes). Check out past polls.