Dear Monks,
While Config::General with Tie::IxHash works very well for me, there is an issue I'm struggling with; The order of the keys are not retained when the configuration file is saved.
#!/usr/bin/perl use strict; use warnings; use Config::General qw{ParseConfig}; use Tie::IxHash; my $file = 'test.cfg'; tie my %CFG, "Tie::IxHash"; %CFG = ParseConfig( -ConfigFile => $file, -Tie => "Tie::IxHash", ); print "When freshly loaded:\n"; print join "\n", keys %CFG; print "\n\n"; (new Config::General( -ConfigHash => \%CFG, -Tie => "Tie::IxHash", ))->save_file($file); # SaveConfig appears "equally bad" at this.. %CFG = ParseConfig( -ConfigFile => $file, -Tie => "Tie::IxHash", ); print "When saved & reloaded:\n"; print join "\n", keys %CFG;
<abc1> opt val </abc1> <abc2> opt val </abc2> <cba1> opt val </cba1> <cba2> opt val </cba2> <test1> opt val </test1> <test2> opt val </test2>
When freshly loaded: abc1 abc2 cba1 cba2 test1 test2 When saved & reloaded: test1 cba2 abc2 abc1 test2 cba1
I would like the original order of those keys retained when the config file is saved and loaded again. Is this possible, or do I need to implement my own "save tied hash order to file" function?
In reply to Retaining hash order with Config::General? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |