#!/usr/local/bin/perl

$FILE = "fml.log";

{
	unless(open(FL, "$FILE")) {
		exit;
	}
	undef(@list, @counter);
	while(<FL>) {
		chomp;
		@data = split(/\s+/, $_);
		if ($data[2] =~ /^ARTICLE$/) {
		@dd = split(/[()]/, $data[4]);

		$cnt = 0;
		while(defined($list[$cnt])) {
			if ($list[$cnt] =~ /^$dd[1]$/) {
				$counter[$cnt]++;
				last;
			}
			$cnt++;
		}
		unless (defined($list[$cnt])) {
			$list[$cnt] = $dd[1];
			$counter[$cnt] = 1;
		}
		}
	}

	$cnt = 0;
	while(defined($list[$cnt])) {
		$cnt1 = 0;
		while(defined($list[$cnt1])) {
			if ($counter[$cnt] > $counter[$cnt1]) {
				$tmp = $list[$cnt];
				$list[$cnt] = $list[$cnt1];
				$list[$cnt1] = $tmp;

				$tmp = $counter[$cnt];
				$counter[$cnt] = $counter[$cnt1];
				$counter[$cnt1] = $tmp;
			}
			$cnt1++;
		}
		$cnt++;
	}

	$cnt = 0;
	$total = 0;
	while(defined($list[$cnt])) {
		$tmp = sprintf("%40s %5d Posts\n", $list[$cnt], $counter[$cnt]);
		$total += $counter[$cnt];
		print $tmp;
		$cnt++;
	}
	$tmp = sprintf("   -=-=-=-=-=-  T O T A L -=-=-=-=-=-    %5d Posts\n", $total);
	print $tmp;
}
