Control order of hashref with YAML::XS

488 views Asked by At

I'm dumping a data structure to YAML with the YAML::XS library:

foo => {
    bar => [
        {...},
        {...},
    ],
    baz => [
        {...},
        {...},
    ], 
    ...
}

It seems like YAML::XS's default behavior is to sort the keys before dumping them, but this is not what I want. Humans will have to read and edit the output of this script, so readability is a concern. Is there a way to control the order that the keys are dumped out so that foo->{baz} would come before foo->{bar}?

1

There are 1 answers

0
ikegami On BEST ANSWER

As you can see from the docs, there is no option that configures the order of hashes. This is further confirmed by looking at dump_node and dump_hash in LibYAML/perl_libyaml.c.