Just Another . . .

>
> <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, {
             anotherrotatethese => sub {

              my @bunches;
              my $error = '';

             $error .= 'Hey, ya gotta supply items to rotate!' unless @_;

            while( my ( $item, $toggle ) = splice( @_, 0, 2 ) )  {
               unless( defined( $item ) and defined( $toggle ) ) {
                    $error .= "Wrong number of arguments passed to
&anotherrotatethese.\n";
                    last;
               }
               if ( $toggle !~ /^\d+$/ or $toggle == 0 ) {
                   $error .= "Toggle '$toggle' is not a positive
integer.\n"; ## watch it
                    last;
               }

               push( @bunches, [ $item, $toggle ] );
          }

        die $error if $error;

        my $count = 0;
        my $index = 0;

        return sub  {
           my $toReturn = $bunches[ $index ][0];
           if ( ++$count % $bunches[ $index ][1] == 0) {
               if ( $index == $#bunches ) { $index = 0 }
              else { $index++ }

              $count = 0;
           }
           $toReturn
      }

       }
     }) or die $template->error();

__END__
[% colors = anotherrotatethese( '#FF0000', 1, '#00FF00', 3, '#0000FF', 4,
'#0F0F0F', 2 );
FOREACH item = [1..15];
  item; " => "; colors; "\n";
END;
%]

JJ

> --
> 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!
>
>
> _______________________________________________
> templates mailing list
> [EMAIL PROTECTED]
> http://www.template-toolkit.org/mailman/listinfo/templates



Reply via email to