develooper Front page | perl.perl5.porters | Postings from March 2013

Re: [perl #117243] Re: Bleadperl v5.17.9-200-g0e0ab62 breaksMLEHMANN/JSON-XS-2.33.tar.gz

Thread Previous
From:
Ricardo Signes
Date:
March 21, 2013 19:18
Subject:
Re: [perl #117243] Re: Bleadperl v5.17.9-200-g0e0ab62 breaksMLEHMANN/JSON-XS-2.33.tar.gz
Message ID:
20130321191828.GA24918@cancer.codesimply.com
* "schmorp@schmorp.de" <perlbug-followup@perl.org> [2013-03-21T04:28:54]
> - I'd say this simply breaks perl, as perl documented the order is fixed,
>   at least between runs (I would argue even the earlier fix to randomise
>   between runs is a bug). Sure, the wording is ambiguous, but that doesn't
>   make it any better.

Unlike many other respondents to this thread, I agree that the wording is
imperfect, and that it is not ludicrous to imagine reading the documentation
for "each" and coming away thinking that the order is going to be the same
between two hashes with the same contents in one run of perl.  I don't think
it's the most likely reading, but of course I have no research on the topic…
let's call that a guess, and throw it out.

So, there are two readings possible here, hinging in part on the meaning of the
phrase "same hash."  Either:

  a. a hash with the same contents always orders keys/value in one way
  or
  b. a particular hash var always does this, with no bearing on other hashes

As Yves showed, it's already the case (in some cases) that
two hashes with the same contents are not ordered the same:

  my %hash=(13=>1,19=>1);
  say join " ", keys %hash;
  my %copy= %hash;
  say join " ", keys %copy;

If the (a) reading was correct, the fact that this program emits two different
lines would be a bug.  If (b), not.

As it stands, it falls to me to decide which reading is canonical.  The answer
is (b).  In my experience, this has been the understanding on list for as long
as I can remember, and was repeated a good bit when the 5.8.1 ordering changes
were made.

This work has been in progress for quite some time, and has been thoroughly
discussed, and it is going to stay in.

--
rjbs

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About