Okay, if a 2-D chart of games to players will work, see what you think of this. The subroutine will handle any number of players, games, and players/game, as long as there are always the same number of players like you mentioned, and it displays a simple ASCII chart of a window between two numbered games. There's no error checking, and the formatting could get messed up with long names, but I think it does the basics.
#!/usr/bin/env perl
use 5.010; use warnings; use strict;
use List::Util qw(max first);
my @players = qw( Adam Bob Clay Dan Ed Frank George );
my @games = ( [1,2,3,4],
[2,3,4,5],
[2,4,5,6],
[2,4,6,7],
[2,4,6,7],
[3,4,6,7],
[1,3,4,7] );
chart( \@players, \@games, 2, 4 ); # print a chart from game 2 to 4
chart( \@players, \@games, 1, 7 ); # print a chart of all 7 games
sub chart {
my $players = shift; # players array
my $games = shift; # games array
my $start = shift; # start game
my $end = shift; # end game
my $pl = max map { length $_ } @$players;
say '-' x 40;
for my $p ( 1..@$players ){
printf "%-${pl}s | ", $players->[$p-1];
for( $start..$end ){
print is_in($p,$games->[$_-1]) ? 'X ' : ' ';
}
say '';
}
say '-' x 40;
printf "%-${pl}s | ", ' ';
print "$_ " for $start..$end;
say '';
}
sub is_in {
return first { $_ == $_[0] } @{$_[1]};
}
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.