The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::Hash::Array - a hash which is internally implemented as a sorted array

SYNOPSIS

  use Tie::Hash::Array;

  tie my %hash, 'Tie::Hash::Array';
  $hash{foo} = 'bar';

  my $object = new Foo;
  $hash{$object} = 'You can also use objects as keys.';

  while ( my($key, $value) = each %hash ) {
      $key->dwim($value) if ref $key && $key->can('dwim');
  }

DESCRIPTION

Hashes tied to this class will interally be stored as an array alternately containing keys and values, with its keys sorted in standard string comparison order, that is, as cmp does.

While the main purpose of this module is serving as a base class for Tie::Hash::Abbrev, some of its side effects may also be useful by themselves:

  • "each" in perlfunc will return the contents in sorted order.

  • You can use objects as keys. (Please note, however, that in this case the string representations of these objects should stay constant, or to be exact, their string sorting order should maintain stable, or else you might get undesired results.)

SUBCLASSING

Please do not rely on the implementation details of this class for now, since they may still be subject to change.

If you'd like to subclass this module, please let me know; perhaps we can agree on some standards then.

BUGS

None known so far.

AUTHOR

        Martin H. Sluka
        mailto:martin@sluka.de
        http://martin.sluka.de/

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

Tie::Hash::Abbrev