Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Add function which returns reference to newly created tied hash #10

Open
pali opened this issue Dec 3, 2019 · 0 comments
Open

Comments

@pali
Copy link

pali commented Dec 3, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant