Tie::Cycle(3)
π« Tie::Cycle(3) π«
okay so bestie, you know how the man page header says Tie::Cycle(3) from the User Contributed Perl Documentation? yeah. that's this. it's the Tie::Cycle module and it's literally about to make your whole scalar situation iconic β¨
πΈ NAME πΈ
Tie::Cycle β cycle through a list of values via a scalar. that's it. that's the whole vibe. no cap π
π¦ SYNOPSIS π¦
like, watch this:
use v5.10;
use Tie::Cycle;
tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF 000000 FFFF00 ) ];
say $cycle; # FFFFFF
say $cycle; # 000000
say $cycle; # FFFF00
say $cycle; # FFFFFF back to the beginning
(tied $cycle)->reset; # back to the beginning
see how it just goes and goes and goes? FFFFFF, 000000, FFFF00, and then boom β back to FFFFFF. it's giving carousel. it's giving main character energy. periodt π
π DESCRIPTION π
so here's the tea, bestie: you use Tie::Cycle to go through a list over and over again. once you hit the end of the list, you go right back to the beginning. and the way you don't even have to worry about any of it? that's the magic of tie doing it all for you. literally iconic π§
the tie takes an array reference as its third argument. the tie should succeed unless the argument is not an array reference. and here's a little lore drop: previous versions required you to use an array that had more than one element (like... what's the point of looping otherwise? π), but that restriction has been removed, because the number of elements you want to use may change depending on the situation. slay for flexibility π
β οΈ okay but this part is important, don't skip it: during the tie, this module makes a shallow copy of the array reference. so if the array reference contains references, and those references are changed after the tie, the elements of the cycle will change as well. π see the included test.pl script for an example of this effect. fr fr, go look at it.
π OBJECT METHODS π
you can call methods on the underlying object β which you access with tied(), iykyk π«Ά
π reset
roll the iterator all the way back to the starting position. the next access will give you the first element in the list. fresh start, clean slate, new era β¨
π previous
give the previous element. and no, this does not affect the current position. it's just a little peek behind you, bestie π
β next
give the next element. this also does not affect the current position. so yes, you can absolutely peek at the next element if you like. no consequences, no drama π
π₯ SOURCE AVAILABILITY π₯
this module is on Github, go be nosy:
https://github.com/briandfoy/tie-cycle
π AUTHOR π
brian d foy, "<briandfoy@pobox.com>" β the legend themselves π
π COPYRIGHT AND LICENSE π
Copyright Β© 2000-2025, brian d foy "<briandfoy@pobox.com>". All rights reserved. this software is available under the Artistic License 2.0. read it, respect it, love it π«Ά
π¦ and that's the whole page bestie!! this one's fromperl v5.32.1, dated2026-01-17, and it's theTie::Cycle(3)man page β now go loop some values, you absolute icon πΈπ β¨
π¦ where this page comes from
- epel 9: perl-Tie-Cycle 1.231-3.el9 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms