.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Tie::Cycle 3pm" .TH Tie::Cycle 3pm 2024-02-08 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Tie::Cycle \- Cycle through a list of values via a scalar. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use v5.10; \& use Tie::Cycle; \& \& tie my $cycle, \*(AqTie::Cycle\*(Aq, [ 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 .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" You use \f(CW\*(C`Tie::Cycle\*(C'\fR to go through a list over and over again. Once you get to the end of the list, you go back to the beginning. You don't have to worry about any of this since the magic of tie does that for you. .PP The tie takes an array reference as its third argument. The tie should succeed unless the argument is not an array reference. Previous versions required you to use an array that had more than one element (what's the pointing of looping otherwise?), but I've removed that restriction since the number of elements you want to use may change depending on the situation. .PP During the tie, this module makes a shallow copy of the array reference. 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 \fItest.pl\fR script for an example of this effect. .SH "OBJECT METHODS" .IX Header "OBJECT METHODS" You can call methods on the underlying object (which you access with \f(CWtied()\fR ). .IP reset 4 .IX Item "reset" Roll the iterator back to the starting position. The next access will give the first element in the list. .IP previous 4 .IX Item "previous" Give the previous element. This does not affect the current position. .IP next 4 .IX Item "next" Give the next element. This does not affect the current position. You can peek at the next element if you like. .SH "SOURCE AVAILABILITY" .IX Header "SOURCE AVAILABILITY" This module is on Github: .PP .Vb 1 \& https://github.com/briandfoy/tie\-cycle .Ve .SH AUTHOR .IX Header "AUTHOR" brian d foy, \f(CW\*(C`\*(C'\fR .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright © 2000\-2024, brian d foy \f(CW\*(C`\*(C'\fR. All rights reserved. This software is available under the Artistic License 2.0.