in reply to Re: Retaining hash order with Config::General?
in thread Retaining hash order with Config::General?

Update: The Config::General->save_file method calls the _store method, which in turn traverses the hash with a keys method on line 1252.

And thereabout is where the problem lies. The module takes extra care of preserving ties on the data (thus on the order, if tied to Tie::IxHash), up to calling this method, store_. And there, it foolishly throws it away:

sub _store { # # internal sub for saving a block # my($this, $level, %config) = @_; ... }
Ouch.

This assignment of the sorted hash data to an ordinary hash %config is where the semi-random order comes from — only to traverse it later on.

Tieing to any hash is useless this way.

I'd call that a bug. I think it'd be better if _store accepted a hashref instead of flat data, to traverse the data tree.

Replies are listed 'Best First'.
Re^3: Retaining hash order with Config::General?
by Anonymous Monk on Dec 15, 2008 at 21:18 UTC

    Thank you all for your replies.

    I will see if I can hack this by passing a hash ref or something. Christmas vacation coming up ;-)