Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: HASH Array advice

by reasonablekeith (Deacon)
on Jan 24, 2006 at 11:43 UTC ( [id://525159]=note: print w/replies, xml ) Need Help??


in reply to HASH Array advice

No real problem, but it should make you think about using an array in there instead....

my %dict; $dict{'label'} = ['label 1', 'label 2']; print Dumper(\%dict);
---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re^2: HASH Array advice
by Anonymous Monk on Jan 24, 2006 at 11:49 UTC
    Thank you for your response...
    So I must change it to something like this?
    %dict =( label => ('label 1', 'label 2') )

    What's the pro's of doing it this way?

      That should be:

      %dict =( label => ['label 1', 'label 2'] )

      Using [ .. ] to create an anonymous array.

      The advantage is that array access is much faster than hash access.

      A good approch would be to code up both alternatives and benchmark them.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Slap me with a wet micro$oft t-shirt for not using [ .. ]
        Had a brain fart for a second using ( .. )

        There's not much difference in the bench mark, but i suppose the size of the array makes a difference... and i predict it will become rather large as my program progresses...
      as said above, an array would be faster, but I mentioned this mainly in a "right tool for the job" type way.

      If you are accessing something based on a numeric index, you might as well be using an array. It's what they were designed for. :)

      ---
      my name's not Keith, and I'm not reasonable.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found