----- Original Message -----
From: "Randal L. Schwartz" <[EMAIL PROTECTED]>
> Well, then, let's go all the way around with a factory:
>
> use Template;
> my $template = Template->new;
> $template -> process ( \*DATA, {
> rotatethese => sub {
> my @things = @_;
> sub { push @things, shift @things; $things[0] };
> },
> }) or die $template->error();
> __END__
> [% colors = rotatethese('#00ff00', '#ff0000', '#0000ff');
> FOREACH item = [1..10];
> item; " => "; colors; "\n";
> END;
> %]
>
> :-)
<humor>Ovid stupidly decides to pick up the gauntlet that Randal threw
down.</humor>
Well, then... what if I only want to rotate after X iterations?
Maybe we can build and an entire module out of a game of email one-upmanship
:)
use Template;
my $template = Template->new;
$template -> process ( \*DATA, {
rotatethese => sub {
my ( $toggle, @items ) = @_;
my $error = '';
if ( $toggle !~ /^\d+$/ or $toggle == 0 ) {
$error = "The first argument to &rotatethese must be a
positive integer.";
}
if ( ! @items ) {
$error .= "Hey, ya gotta supply items to rotate!";
}
die $error if $error;
my $count = 0;
my $index = -1;
return sub {
$index += 1 if $count++ % $toggle == 0;
$index = 0 if $index == @items;
$items[ $index ];
}
}
}) or die $template->error();
__END__
[% colors = rotatethese(3, '#00ff00', '#ff0000', '#0000ff');
FOREACH item = [1..10];
item; " => "; colors; "\n";
END;
%]
--
Cheers,
Curtis "Cheeky S.O.B." Poe
Senior Programmer
ONSITE! Technology, Inc.
www.onsitetech.com
503-233-1418
Taking e-Business and Internet Technology To The Extreme!