8

According to the answer to this question, merging two hashes in Perl 5 can be done either with:

%newHash = (%hash1, %hash2); %hash1 = %newHash;

or:

@hash1{keys %hash2} = values %hash2;

On the other hand, Perl 5.18 will introduce per process hash randomization.

Will the second method still be correct to use in Perl 5.18?

Community
  • 1
  • 1
andrefs
  • 555
  • 4
  • 14
  • 3
    BTW there's no need to use `%newHash` in the first example. You can just say `%hash1 = ( %hash1, %hash2 );` – friedo Jan 22 '13 at 17:56
  • Yeah I also thought of that. I just copied the examples from the answer to linked question, my main focus was the other example. Thanks for the clarification though. – andrefs Jan 22 '13 at 17:59

1 Answers1

15

After reading through Re^2: Hash order randomization is coming, are you ready?, the answer is yes. As before, keys, values and each will produce the same sequence iterating through the hash inside the same process if the hash isn't changed in between.

ikegami
  • 367,544
  • 15
  • 269
  • 518
Perleone
  • 3,958
  • 1
  • 26
  • 26
  • 3
    if anything it will be more likely to work as in perl's between 5.8.1 and 5.18 there was a small chance perl would rehash the hash with a random seed if it detected an attack. this would lead to the order changing. In 5.18 the seed remains constant for the life of the process – user1937198 Jan 22 '13 at 17:21
  • 1
    @user1937198 it's exactly as likely to work, because it always was (and still is) guaranteed that `keys` and `values` on the same hash return corresponding lists as long as the hash is not modified between the two calls. – hobbs Jan 22 '13 at 17:34