Skip to content

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

Description

@pali

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions