randomize array template-toolkit

randomize array template-toolkit
Here is a mini-‌cgi to show how to install it into the Template list operations.
use strict;
use CGI qw( header start_html );
use Template;
use List::Util;
$Template::Stash::LIST_OPS->{shuffle} = sub { List::Util::shuffle @{ +shift || [] }; };
my $tt2 = Template->new();
print header(), start_html(-title => "Template::Toolkit Shuffle");
my @cards = ( 2 .. 10, qw( A K Q J ) ); my @deck;
for my $suit ( qw( S H C D ) ) { push @deck, map { "$_$suit" } @cards; }
$tt2->process(\*DATA, { deck => \@deck }) or warn $Template::ERROR;
__DATA__ <h1>Template::Toolkit Shuffle</h1> [% FOR i IN deck.shuffle %] [% i %] [% '<br />' UNLESS loop.count % 5 %] [% END %]
Should give you something like:

Template::Toolkit Shuffle

10C 6H 9D JD 9S
5D 4S 3S 4H KD
7H 7S 8S 8H 7D
KH AS QD 5H AC
QC 7C 10D 3H 5S
10S 6D JC AH QS
8C 8D 3D 2H JH
3C KS 6C KC 4D
JS 9H 6S 4C 2D
AD 9C 10H 2S QH
5C 2C
You can also do it the easy way: Template::Plugin::ListUtil. Wuss.
[close] Permanent link · http://querylog.com/q/randomize+array+template-toolkit

Suggested HTML for linking:
Link preview: randomize array template-toolkit
13 October 2005 · Internet & computing
The page found by the original query:
Code snippets in Perl and JavaScript
Browse by the page—15 Q&R each
« previous | more »