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:
Brandon Allbery
Date:
September 30, 2017 02:25
Subject:
Re: Any way to get hashes to loop in order?
Message ID:
CAKFCL4VPPRaX1PHU-Rms4EY8LFjUDVDE_dQMpo7q2gPGAMJS6Q@mail.gmail.com
On Fri, Sep 29, 2017 at 9:55 PM, ToddAndMargo <ToddAndMargo@zoho.com> 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
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

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