in reply to Re: Hash assignment misunderstanding
in thread Hash assignment misunderstanding

I would also be very suspicious of relying on keys and values having the same order, they probably will (might even be guaranteed) but I'd still prefer not to have an unsorted keys call as a hash slice. Instead of:
@$default{ keys %$config } = values %$config;
...I'd probably write:
my @ids = keys %$config; @$default{ @ids } = @$config{ @ids };
...this is also less likely to get updated to be "bad".
--
And-httpd, $2,000 security guarantee
James Antill

Replies are listed 'Best First'.
Re^3: Hash assignment misunderstanding
by hardburn (Abbot) on Sep 06, 2006 at 16:35 UTC

    keys() and values() are guarenteed to be the same as long as you don't modify the hash in between calls.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re^3: Hash assignment misunderstanding
by wfsp (Abbot) on Sep 06, 2006 at 16:43 UTC
    From the docs:

    The keys are returned in an apparently random order, but it is the same order as either the values() or each() function produces (given that the hash has not been modified).