#!/usr/bin/perl

use 5.038;

unless ( -e $ARGV[0] && -f $ARGV[0] ){
    say "Usage: $0 <plain textfile of a list>";
    say "";
    say "Format of the file line: Blah blah blah = x";
    say "                         wow wow wow = y   ";
    say "Comments begin a line with #"; 
    say "and where 'x,y' are one of the numbers:";
    say "CODE -> SIGNIFICATION";
    say "0 -> NOT OK";
    say "1 -> OK";
    say "2 -> OK with flying colors";
    exit -3;
}

open my $fh, '<', $ARGV[0] or die $!;
my ($line, $c);
my ($fatal, $ok, $qualify) = (0,0,0);
while ($line = <$fh>){
    chomp $line;
    next if ($line =~ /^#/);
    next unless ($line =~ /\=/ && $line =~ /[0-2]/);
    my ($description, $number) = split /\=/, $line;
    $number =~ s/\s+//g;
    unless ($number =~ /\d/){
	say "Not found a single number on line ", $c+1;
	next;
    }
    ++$c;
    if ($number == 0){
	say "FATAL: NOT OK in $description";
	$fatal++;
    }elsif ($number == 1){
	$ok++;
    }elsif ($number == 2){
	$qualify++;
    }else{
	say "IGNORED: $line";
	$c-- if ($c > 0);
    }
}
close $fh;
say "Data readed. $c valid lines";
die "Exiting." if ($c <= 0);
say "";

say "-" x 60;
say "Some stats:";
say "";
say "Fatal acomplishment counter = $fatal lines";
say "Only OK lines counter       = $ok lines";
say "Really good characteristics = $qualify lines";
say "";
die "Bad stats for evaluation. Exiting." if ($fatal > 0);
die "Bad stats. Fault lines or not OK. Exiting." unless ($qualify > 0 || $ok > 0);
say "So, let's say $ARGV[0] have ", 100*$qualify/($ok+$qualify), "% of superior characteristics";
say "";
say "-" x 60;

exit 2;


