Tie::A...Sorted(3pm)

πŸ“¦
version 1.41 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ‘‘ Tie::Array::Sorted β€” the manual page, but make it a group chat ✨

okay so bestie, imagine an array. normal array vibes, right? but this one? this one is Tie::Array::Sorted β€” an array which is kept sorted, always, no cap. it's a Perl module, it lives in the big Perl manual pages (3pm, section 3, iykyk), and by the end of this page you're gonna be obsessed. periodt. πŸ’…


πŸ¦‹ SYNOPSIS

use Tie::Array::Sorted;

tie @a, "Tie::Array::Sorted", sub { $_[0] <=> $_[1] };

push @a, 10, 4, 7, 3, 4;
print "@a"; # "3 4 4 7 10"

see how we pushed chaos in and order came out?? that's the whole vibe. πŸŽ€


🌸 DESCRIPTION

okay so this thing presents you a totally ordinary array... except it's kept sorted. all your pushes and unshifts cause the elements in question to get inserted at the appropriate location to maintain order. like the array has a little internal bouncer who's like "nah babe, you go here". πŸ’–

Direct stores ($a[10] = "wibble") effectively splice out the original value and insert the new element. honestly? it's not clear why you'd want to use direct stores like that, but this module does the right thing if you do. it's highkey giving "no thoughts, correct behavior". πŸ™ˆ

If you don't like the ordinary lexical comparator, you can provide your own β€” it should compare the two elements it is given. for instance, a numeric comparator would look like this:

tie @a, "Tie::Array::Sorted", sub { $_[0] <=> $_[1] }

whereas to compare a list of files by their sizes, you'd so something like:

tie @a, "Tie::Array::Sorted", sub { -s $_[0] <=> -s $_[1] }

like. custom sort logic. you're the main character now. πŸ‘‘


😴 LAZY SORTING

if you do more stores than fetches, you may find Tie::Array::Sorted::Lazy more efficient. it's the chill low-effort cousin. do less, sort later. slay. ✨


πŸ’œ AUTHOR

  • Original author: Simon Cozens
  • Current maintainer: Tony Bowden

🚨 BUGS and QUERIES

Please direct all correspondence regarding this module to:

bug-Tie-Array-Sorted@rt.cpan.org

This module was originall written as part of the Plucene project. However, as Plucene no longer uses this, it is effectively unmaintained.

πŸ’€ bestie. the "originall" typo is in the original, we keep it, we respect it. and yes... "effectively unmaintained" is a real sentence. it's giving vintage. it's giving archival. use with love and a backup plan.

Copyright (C) 2003-2006 Simon Cozens and Tony Bowden.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License; either version 2 of the License,
or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.

so basically: GNU GPL, version 2 or (at your option) any later version. free as in "go off". 🌈 and fr fr β€” no warranty, no implied warranty of merchantability, none of that. the module is serving looks, not legal guarantees. 🫢


and that's the whole page, babe πŸ’– you read a Perl manpage. iconic. ate. no crumbs.

this whole thing came straight out of the Perl documentation β€” perl v5.36.0, dated 2022-10-15 β€” and Tie::A...Sorted(3pm) got its lil name squished in the title up there, just like the header says. go tie an array, keep it sorted, and text me when it works. mwah. πŸ’…πŸŽ€

πŸ“¦ where this page comes from