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.
In reply to Re^3: How to iterate thru entire array with start point other than beginning
by hippo
in thread How to iterate thru entire array with start point other than beginning
by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |