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::Array::Sorted - An array which is kept sorted

SYNOPSIS

  use Tie::Array::Sorted;
  tie @a, "Tie::Array::Sorted";
  push @a, 10, 4, 7, 3, 4;
  print "@a"; # "3 4 4 7 10"

DESCRIPTION

This presents an ordinary array, but is kept sorted. All pushes and unshifts cause the elements in question to be inserted in the appropriate location to maintain order.

Direct stores ($a[10] = "wibble") effectively splice out the original value and insert the new element. It's not clear why you'd want to use direct stores like that, but this module does the right thing if you do.

If you don't like the ordinary numeric comparator, you can provide your own; it should compare the two elements it is given:

    tie @a, "tie::Array::Sorted", sub { $_[0] cmp $_[1] }

AUTHOR

Simon Cozens, <simon@kasei.com>

COPYRIGHT AND LICENSE

Copyright 2003 by Kasei

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