Gossamer Forum
Home : General : Perl Programming :

rotate ( i think come one may need it )

Quote Reply
rotate ( i think come one may need it )
  
copy from other place.


my $next_file = rotate( qw/FileA FileB FileC Filed / );
print $next_file->(), "\n" for 1 .. 50;
sub rotate {
my @list = @_;
my $index = -1;
return sub {
$index++;
$index = 0 if $index > $#list;
return $list[ $index ];
};
}