develooper Front page | perl.perl6.users | Postings from September 2017

Re: Any way to get hashes to loop in order?

Thread Previous | Thread Next
From:
ToddAndMargo
Date:
September 30, 2017 21:00
Subject:
Re: Any way to get hashes to loop in order?
Message ID:
77fe1d63-4ce2-c0aa-c593-e61c6bee1444@zoho.com
On 09/29/2017 07:25 PM, Brandon Allbery wrote:
> The point of a hash is that it computes hash values from its keys for 
> fast lookup,

Not me.  I use them to "organize" data all in one easy to look
up place.  For example:

my %SmtpIni = [
     'DebugTrace' => "",
     'smtp'       => "",
     'port'       => "",
     'username'   => "",
     'password'   => "",
     'from'       => "",
     'to'         => @[""],
     'Subject'    => "",
     'Text'       => "",
     'FileName'   => @[""] ];

You will notice that all the smtp information is organized
in one variable for easy retrieval.  And that %SmtpIni<password>
is absolutely obvious what password it refers to.  No guessing
involved.  No trying to figure out who goes to whom, especially
when using a global variables (which I try to keep to a minimum).

It is all about organization and readability for me, not speed.
If I wanted speed, I would go to the dark side and learn C.

The solution is to create and "index" of the hash and loop
on the index instead of the has if I want to see things in order.
That actually sounds like a fun code.

-T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About