Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi gravid,

As far as I can tell from a glance at the source, Perl only checks those environment variables once on startup (the function Perl_get_hash_seed in util.c sets the variables PL_hash_rand_bits_enabled and PL_hash_rand_bits). It might be possible to change the values at runtime from XS code, but that's not my area of expertise.

But I think it's important to point out that hash ordering has always been random, even though older Perls used to return hash keys with some consistency to the ordering, leading to code sometimes relying on this fact. But at least since v5.18.0 that has changed, see Hash overhaul. The bottom line is, one shouldn't rely on the order hash keys are returned in, in any version of Perl.

I find the easiest solution is usually something like for my $key (sort keys %hash) ..., or in some cases modules like Tie::IxHash can help. See also How do I sort a hash (optionally by value instead of key)? This might be the "better way" to fix your code than to rely on Perl's hash ordering.

Hope this helps,
-- Hauke D


In reply to Re: setting PERL_PERTURB_KEYS & PERL_HASH_SEED in a perl file by haukex
in thread setting PERL_PERTURB_KEYS & PERL_HASH_SEED in a perl file by gravid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found