E.g.
sub new_hash_ref {
tie my %hash, "Hash::Ordered", @_;
return \%hash
}
So construction of new ordered hash would be simple and also its usage. E.g.
my $h = new_hash_ref(key6 => value6, key2 => value2, key3 => value3);
print Dumper [ keys %{$h} ];
print encode_json($h);
and output would be:
$VAR1 = [
'key6',
'key2',
'key3'
];
{"key6":"value6","key2":"value2","key3":"value3"}
This would allow to use other modules (like JSON encoder) to traverse hash keys in specified order and e.g. allow user to easily generate JSON hash with keys in order as he want. And it would work with any Perl module which use just plain keys function without sorting them.
E.g.
So construction of new ordered hash would be simple and also its usage. E.g.
and output would be:
This would allow to use other modules (like JSON encoder) to traverse hash keys in specified order and e.g. allow user to easily generate JSON hash with keys in order as he want. And it would work with any Perl module which use just plain
keysfunction without sorting them.