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.
|