in reply to Re^8: Keeping Order with YAML::XS (sort keys)
in thread Keeping Order with YAML::XS

It was well documented in earlier posts that the ordering of Tie::IxHash was not preserved when serializing to YAML. It would be shocking if any of the CPAN YAML modules had special code to recognize an IxHash. Instead they just see it as a normal hash and proceed properly from there (ie. with freedom to sort keys). The solution has been presented above -- transform the IxHash into an array of hashes each containing a single key/value pair. That is a data structure that will work and answers the question posed by the OP.

All that remains is for some code to be written.

Still, a lot of code other than YAML::XS will ignore IxHash ordering...

use Data::Dump qw(pp); use Tie::IxHash; tie my(%hash), 'Tie::IxHash', (a => 1, c => 3, b => 2); pp \%hash;
Output:
{ # tied Tie::IxHash a => 1, b => 2, c => 3, }

Replies are listed 'Best First'.
Re^10: Keeping Order with YAML::XS (sort keys)
by Anonymous Monk on Jul 29, 2013 at 11:08 UTC

    Still, a lot of code other than YAML::XS will ignore IxHash ordering..

    Yeah, with sort keys, and thats a bug