User:WarX/counter.pl

#! /usr/bin/perl -w

while (<>)
{
	if (m!^\*\s*'''\s*(.*?)\s*'''!)
	{
		my $temp = $1;
		$temp =~ s/\D+/ /gi;
		$temp .= " " unless $temp =~ / $/;
		my @list = ($temp =~ m!(\d*) !gc);
#		print $temp, "-->", join " ", @list, "\n";
		if (scalar @list > 5)
		{
			print STDERR "error: $temp-", join "-", @list, "\n";
		}
		else
		{
			for (@list)
			{
				$points{$_}++;
			}
		}
	}
}

$max = 0;

for (1..321)
{
	$points{$_} = 0 if not defined $points{$_};
	$max = $points{$_} if ($points{$_} > $max);
}

$leaders = "";

for (1..321)
{
	$leaders .= "$_ " if ($points{$_} == $max);
}

for (sort {$a <=> $b} keys %points)
{
	print "|-\n"if ($_ % 10 == 1);
	print "|$_: $points{$_}" , ( $_ % 10 == 0 ? "\n" : "|");
}

print "|colspan=\"7\"| ||colspan=\"2\" style=\"background:#CCF\"|(Leader: '''$leaders''')\n";