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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The fundamental key IMHO is this. As long as you are doing a lot of thinking involving positional logic, you are not being very Perlish.

I just wanted to qualify this statement with a slightly tangential one of my own -- as a newbie, when you discover the power of hashes in Perl they become intoxicating. Oh, this could be a hash. Oh, and so can this. And this. And this. And...

tilly's very erudite description of the hash glosses over this slightly, but only because, as a saint, he's probably forgotten how we men and women in the trenches think.

It is important to remember that hashes have higher overhead and are slower to access than an array, but, in contrast, accessing a hash is essentially a constant time operation -- meaning, that as long as I know what item I want, it takes the same amount of time to access the 1st element of the hash as the nth.

There is a lot of overlap between arrays and hashes conceptually in Perl (and even more so under the hood), and you need to keep in mind how you are intending to use your data structure and the kind of data it will hold. For instance, a few general examples:

  • When order is important for adding/accessing: array
  • When keyword access is important for adding/accessing: hash
  • When numeric values are your keys: dense data = array, sparse data = hash

The rules/ideas go on for many lines from there, but I guess what I'm getting at, is that Perl makes it possible to see the world through hash-tinted glasses <pun intended>, but always keep in mind that the lowly array is an equally adept tool for many jobs.


In reply to Re: Re (tilly) 1: Hash Tutorial by jreades
in thread Hash Tutorial by dhammaBum

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found