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

2017-09-30 Thread ToddAndMargo
On Sep 30, 2017 12:41 PM, "Parrot Raiser" <1parr...@gmail.com 
> wrote:


Prepending the real key value with an order indicator, then sorting
the retrieved list on the key would achieve that, (though the maximum
number size would have to be known in advance.

E.g. 001First_key => data1, 002Second => data2



On 09/30/2017 01:59 PM, Brock Wilcox wrote:
Maybe a list/array of pairs would be better, and then cast it to a hash 
if you need to do fast lookups.




I was going to create an "index" of the keys in an regular
array.  Then create the hash using the index.  When I
wanted to print things in order, loop on the index array,
not the hash.


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

2017-09-30 Thread Brock Wilcox
Maybe a list/array of pairs would be better, and then cast it to a hash if
you need to do fast lookups.

On Sep 30, 2017 12:41 PM, "Parrot Raiser" <1parr...@gmail.com> wrote:

> Prepending the real key value with an order indicator, then sorting
> the retrieved list on the key would achieve that, (though the maximum
> number size would have to be known in advance.
>
> E.g. 001First_key => data1, 002Second => data2
>


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

2017-09-30 Thread ToddAndMargo

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
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


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

2017-09-30 Thread Parrot Raiser
Prepending the real key value with an order indicator, then sorting
the retrieved list on the key would achieve that, (though the maximum
number size would have to be known in advance.

E.g. 001First_key => data1, 002Second => data2


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

2017-09-29 Thread ToddAndMargo

On 09/29/2017 07:25 PM, Brandon Allbery wrote:
On Fri, Sep 29, 2017 at 9:55 PM, ToddAndMargo > wrote:


for %SmtpIni.kv -> $key, $value { say $key; }

Does "say" the keys in the order that I created them.

Is there a way to get them to do so?


Not without storing that order somewhere yourself and using it to 
retrieve values. The point of a hash is that it computes hash values 
from its keys for fast lookup, and to the extent that any order can be 
said to exist for keys in a hash, it will be related somehow to those 
hash values. As a practical matter, Hashes are not considered to have 
any ordering.


Poop!

Thank you for the education.

-T


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

2017-09-29 Thread Brandon Allbery
On Fri, Sep 29, 2017 at 9:55 PM, ToddAndMargo  wrote:

> for %SmtpIni.kv -> $key, $value { say $key; }
>
> Does "say" the keys in the order that I created them.
>
> Is there a way to get them to do so?
>

Not without storing that order somewhere yourself and using it to retrieve
values. The point of a hash is that it computes hash values from its keys
for fast lookup, and to the extent that any order can be said to exist for
keys in a hash, it will be related somehow to those hash values. As a
practical matter, Hashes are not considered to have any ordering.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


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

2017-09-29 Thread ToddAndMargo

On 09/29/2017 06:55 PM, ToddAndMargo wrote:

Hi List,

for %SmtpIni.kv -> $key, $value { say $key; }

Does "say" the keys in the order that I created them.

  Does not

Stinking typos



Is there a way to get them to do so?


Many thanks,
-T



--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Any way to get hashes to loop in order?

2017-09-29 Thread ToddAndMargo

Hi List,

for %SmtpIni.kv -> $key, $value { say $key; }

Does "say" the keys in the order that I created them.

Is there a way to get them to do so?


Many thanks,
-T