Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    List::Rotation 1.007

    Download button

    No screenshots available
    Downloads: 306  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Good (3.3/5)
    6 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Imre Saling | More programs
    Perl Artistic License / FREE
    December 16th, 2007, 11:11 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    List::Rotation description

    List::Rotation allows to loop through a list of values via a singleton object implemented as closure.

    List::Rotation allows to loop (Cycle, Alternate or Toggle) through a list of values via a singleton object implemented as closure.

    SYNOPSIS

    use List::Rotation;

    my @array = qw( A B C );

    my $first_cycle = List::Rotation::Cycle->new(@array);
    my $second_cycle = List::Rotation::Cycle->new(@array); ## the same object is returned as above

    print $first_cycle->next; ## prints A
    print $second_cycle->next; ## prints B
    print $first_cycle->next; ## prints C
    print $second_cycle->next; ## prints A, looping back to beginning

    my $alternation = List::Rotation::Alternate->new( qw( odd even ) );

    print $alternation->next; ## prints odd
    print $alternation->next; ## prints even
    print $alternation->next; ## prints odd
    $alternation->reset; ## reset the alternation to first item
    print $alternation->next; ## prints odd

    my $switch = List::Rotation::Toggle->new;

    ## prints even numbers between 2 and 10
    foreach ( 2..10 ) {
    print "$_n" if $switch->next;
    }

    Use List::Rotation to loop through a list of values. Once you get to the end of the list, you go back to the beginning.
    List::Rotation is implemented as a Singleton Pattern. You always just get 1 (the very same) Rotation object even if you use the new method several times with the same set of parameters. This is done by using Memoize on the new method. It returns the same object for every use of new that comes with the same list of parameters.

    The class List::Rotation contains three subclasses:

    List::Rotation::Cycle

    Loop through a list of arbitrary values. The list must not be empty.

    List::Rotation::Alternate

    Alternate two values.

    List::Rotation::Toggle

    Toggle between true and false.

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    singleton object | loop lists | Perl module | loop | cycle | singleton

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM