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

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

Thread Previous | Thread Next
September 30, 2017 21:00
Re: Any way to get hashes to loop in order?
Message ID:
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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About