Tie::A...::Lazy(3pm)
β¨ NAME β¨
Tie::Array::Sorted::Lazy β it's an array, bestie, and it stays sorted π
πΈ SYNOPSIS πΈ
use Tie::Array::Sorted::Lazy;
tie @a, "Tie::Array::Sorted::Lazy", sub { $_[0] <=> $_[1] };
push @a, 10, 4, 7, 3, 4;
print "@a"; # "3 4 4 7 10"
π¦ DESCRIPTION π¦
okay so picture Tie::Array::Sorted but with main character energy for a very specific situation: arrays where you're writing way more than you're reading. Like, you're pushing stuff in constantly and hardly ever peeking at it. That's the vibe this module was built for π
The way it works is genuinely iconic: instead of re-sorting the array every single time you insert something, it chills and lets the sorting happen on retrieval instead. So the work gets deferred until the moment you actually go looking at the array. Slay.
And the extra smart part? It only re-sorts if the data has actually been modified since the last sort. So if nothing changed and you fetch twice, the second fetch is just... free. No wasted effort, no drama. Periodt β¨
Here's another way you might set it up, comparing by file size with the -s operator:
tie @a, "Tie::Array::Sorted::Lazy", sub { -s $_[0] <=> -s $_[1] };
and that's the whole page, bestie π«Ά this one's from the User Contributed Perl Documentation, running on perl v5.36.0 and dated 2022-10-15 β go keep your arrays cute and sorted π
π¦ where this page comes from
- ubuntu noble: libtie-array-sorted-perl 1.41-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtie-array-sorted-perl 1.41-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtie-array-sorted-perl 1.41-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms