Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Sorting a hash in a predetermined order

by ctilmes (Vicar)
on Nov 18, 2015 at 01:48 UTC ( #1147966=note: print w/replies, xml ) Need Help??


in reply to Sorting a hash in a predetermined order

I agree with others, hard code the list.

This is going to eventually be used as a nagios check and it would be great if the output could be in a consistent order.

BTW -- if all you want is a consistent order, that will be true. As long as you have the same set of hash keys, they will output in the same consistent order. (at least for the same version of perl..)

If you want them in a specific order, that's when you need one of the other solutions.

  • Comment on Re: Sorting a hash in a predetermined order

Replies are listed 'Best First'.
Re^2: Sorting a hash in a predetermined order
by Athanasius (Archbishop) on Nov 18, 2015 at 03:18 UTC

    Hello ctilmes,

    As long as you have the same set of hash keys, they will output in the same consistent order. (at least for the same version of perl..)

    Not since v5.18.0! From perl5180delta:

    By default, two distinct hash variables with identical keys and values may now provide their contents in a different order where it was previously identical.
    ...
    The seed used by Perl's hash function is now random. This means that the order which keys/values will be returned from functions like keys(), values(), and each() will differ from run to run.

    Of course, the order will remain consistent for a given, unchanged, hash variable throughout a single run of the program. But that won’t satisfy the OP’s requirements.

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1147966]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-08-08 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?