in reply to Re^2: Human-readable serialization formats other than YAML?
in thread Human-readable serialization formats other than YAML?

(Got, Expected) => (Expected, Got)

Please note that the key return order in a hash is not guaranteed by perl. While it will be constant for a given version of perl on one OS it may well change with a different version of perl or even the same version on a different OS. This has bitten me before when writing tests for CPAN modules. If you are stringifying hashes for comparison purposes make sure you apply a sort to the keys first.

Replies are listed 'Best First'.
Re^4: Human-readable serialization formats other than YAML?
by parv (Parson) on Apr 24, 2008 at 01:02 UTC

    I was under the impression that the order of unsorted hash keys is not even guaranteed for *each invocation* of perl for any version of perl in any environment ...

    # Perl 5.8.7, perldoc -f keys keys HASH ... The keys are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the "values" or "each" function produces (given that the hash has not been modified). Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see "Algorithmic Complexity Attacks" in perlsec). ...

    ... ok, at least not since version 5.8.1.

      It bit me back in the 5.6 days in the context of cross platform and different perl versions with stringified hash comparisons in test.t files. The data was the same, but the order was different so the tests failed. At least nowadays it looks like it should bite you immediately instead of after uploading your pride and joy to CPAN only to have it fail tests here, there, and everywhere! Thanks for the info.