in reply to Re: Perl Example of Control Break Processing
in thread Perl Example of Control Break Processing

It would be good for you to wrap your code with code tags instead of pre tags, so a download code link would appear.

I didn't use <code></code> tags for this script simply because PerlMonks doesn't display the Unicode suit characters ♠, ♥, ♦ and ♣ properly when I do. See these discussions of the topic.

Here's what the same script looks like when I enclose it in <code></code> tags:

#!perl use strict; use warnings; use utf8; use open qw( :encoding(UTF-8) :std ); use List::Util qw( shuffle ); @ARGV == 1 or die "Usage: perl $0 <total rounds>\n"; my $TOTAL_ROUNDS = shift; my @players = qw( Bob Carol Ted Alice ); my $player_to_dealers_right = $players&#91;-1&#93;; # Alice my $round = 1; my %hand_of; my @deck; my @cards; for my $rank (qw( 2 3 4 5 6 7 8 9 10 J Q K A )) { for my $suit (qw( &#9824; &#9829; &#9830; &#9827; )) { push @cards, $rank . $suit; } } ROUND: while ($round <= $TOTAL_ROUNDS) { @deck = shuffle(@cards); SHUFFLE: while (@deck) { PLAYER: for my $player (@players) { push @{ $hand_of{$player} }, pop @deck; } if (@{ $hand_of{$player_to_dealers_right} } == 5) { print "Round $round\n"; for my $player (@players) { my $hand = join ' ', @{ $hand_of{$player} }; print "$player has $hand\n"; } print "\n"; %hand_of = (); last ROUND if ++$round > $TOTAL_ROUNDS; } } } __END__ Round 1 Bob has 7&#9829; 8&#9824; Q&#9829; 2&#9830; 9&#9829; Carol has 6&#9830; Q&#9824; 2&#9824; A&#9824; 3&#9830; Ted has K&#9829; 10&#9830; 5&#9830; 7&#9824; A&#9829; Alice has J&#9824; 10&#9829; 6&#9827; 6&#9829; K&#9824; Round 2 Bob has A&#9827; A&#9830; 9&#9827; 4&#9827; 2&#9829; Carol has 7&#9827; 4&#9830; 4&#9829; 8&#9829; 8&#9827; Ted has 6&#9824; J&#9827; K&#9830; 3&#9827; 9&#9824; Alice has 9&#9830; 7&#9830; Q&#9830; 8&#9830; 10&#9827; Round 3 Bob has 5&#9824; K&#9827; 3&#9824; 7&#9830; 7&#9829; Carol has 5&#9827; Q&#9827; 2&#9827; 9&#9827; Q&#9830; Ted has 3&#9829; 4&#9824; 10&#9824; J&#9830; 5&#9829; Alice has J&#9830; 5&#9829; J&#9829; A&#9824; 10&#9824; Round 4 Bob has K&#9827; J&#9829; 7&#9824; 4&#9824; J&#9824; Carol has 10&#9830; 9&#9830; Q&#9829; 9&#9829; 6&#9829; Ted has 10&#9827; 4&#9830; 4&#9827; 3&#9827; K&#9829; Alice has A&#9827; 5&#9830; 2&#9830; 3&#9830; 8&#9827; Round 5 Bob has 5&#9827; 2&#9827; 6&#9824; K&#9830; 2&#9824; Carol has A&#9830; 5&#9824; 6&#9827; 10&#9829; 4&#9829; Ted has 2&#9829; 9&#9824; A&#9829; Q&#9824; 7&#9827; Alice has 3&#9829; Q&#9827; K&#9824; 8&#9830; 8&#9824; Round 6 Bob has J&#9827; 2&#9824; J&#9829; 9&#9829; 6&#9824; Carol has 8&#9829; 10&#9827; 9&#9827; 5&#9827; 4&#9830; Ted has 3&#9824; K&#9829; K&#9827; A&#9830; Q&#9827; Alice has 6&#9830; 9&#9824; 3&#9829; 8&#9830; 9&#9830; Round 7 Bob has Q&#9829; 8&#9829; Q&#9830; 5&#9829; 3&#9827; Carol has 6&#9829; 10&#9829; 5&#9830; 7&#9827; 2&#9830; Ted has 10&#9830; 4&#9824; 4&#9829; 8&#9824; 7&#9830; Alice has J&#9824; 7&#9829; J&#9830; K&#9830; 2&#9827; Round 8 Bob has J&#9827; Q&#9824; 5&#9824; A&#9824; Q&#9824; Carol has 6&#9827; 8&#9827; A&#9829; A&#9827; 5&#9830; Ted has 10&#9824; 3&#9830; 3&#9824; 4&#9827; 6&#9829; Alice has 2&#9829; 6&#9830; K&#9824; 7&#9824; 7&#9824; Round 9 Bob has 3&#9829; 9&#9829; 8&#9830; 2&#9830; 7&#9827; Carol has 10&#9824; 6&#9830; 2&#9827; 4&#9827; J&#9824; Ted has 5&#9827; 4&#9829; 4&#9824; 3&#9824; 3&#9827; Alice has J&#9830; 7&#9830; 2&#9824; 8&#9829; Q&#9827; Round 10 Bob has 7&#9829; 10&#9830; J&#9829; A&#9827; 8&#9827; Carol has 9&#9830; 5&#9829; K&#9824; A&#9829; K&#9829; Ted has 5&#9824; 8&#9824; 4&#9830; 9&#9827; 2&#9829; Alice has A&#9830; 9&#9824; 6&#9824; 3&#9830; J&#9827;