#!/usr/local/bin/perl # Arrange for standard decks for all participants =pod this is the idiot's delight card shuffler, version 1.000 implementation goals: take a command line argument and write that many lines to a file called decks.dat in the current directory each line represents a shuffled deck of cards. =cut $Count = $ARGV[0]; unless ($Count > 0){ die <<"END"; Shuffling instructions: $0 N N is how many decks you would like prepared into decks.dat END }; open(DECKS,">decks.dat")or die "I must be able to write to ./decks.dat, you ninny!\n"; @NewDeck = qw{ Ah 2h 3h 4h 5h 6h 7h 8h 9h Th Jh Qh Kh Ac 2c 3c 4c 5c 6c 7c 8c 9c Tc Jc Qc Kc Ad 2d 3d 4d 5d 6d 7d 8d 9d Td Jd Qd Kd As 2s 3s 4s 5s 6s 7s 8s 9s Ts Js Qs Ks }; sub shuffle(@){ # return a rearranged copy of @_; my @Deck = @_; my $i = 0; my $ii; #benchmark with and without this line? # it's not on critical pathhhhh foreach (@_){ $temp = $Deck[$ii = rand @Deck]; $Deck[$ii] = $Deck[$i]; $Deck[$i++] = $temp; }; return @Deck; }; =pod The server will serve decks until it runs out of them. =cut while($Count-- > 0){ $ThisDeck = join(' ',shuffle(@NewDeck)); print $ThisDeck,"\n"; print DECKS $ThisDeck,"\n"; };