in reply to Re^2: How to iterate thru entire array with start point other than beginning
in thread How to iterate thru entire array with start point other than beginning
If you want to use the % operator, it can be quite simple. To expand on the GP anonymonk's script:
#!/usr/bin/env perl use strict; use warnings; # Set an array of names my @names = qw/January February March April May June July August September October November December/; # Find the index number of next month my $next = (localtime)[4] + 1; # Loop over the next 12 months and print the month names in sequence for my $monpos ($next .. $next + 11) { print "Month is $names[$monpos % 12]\n"; }
Please ask if anything in this piece of code is unclear.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to iterate thru entire array with start point other than beginning
by dirtdog (Monk) on Sep 02, 2016 at 00:40 UTC |