#!/usr/bin/perl -w
# Read FileList to find out how many ratings each student did May 17, 2013
# perl PlCountStudentParticipation.txt FileList24.txt > StudentCount.txt

use strict;
srand(time|$$);

sub ReadFile
{
    my ($FileName) = @_;
    unless(open(MYFILE, $FileName))
    {
        print "Cannot open file $FileName.doc\n";
        exit;
    }
    my @Data = <MYFILE>;
    close MYFILE;
    return @Data;
}

my $FileList = $ARGV[0];
my @DataL = ReadFile($FileList);

my $RecNum = 0;

# Report: 26175
# Discovered repressing masculine side to attract boys. Greater commitment in relationship, clarity on what needs doing. Daughter observed that I looked and felt better.
# A - Creative visuals
# PA - Ego-loss
# P - Loss of contact with reality

my @Records = ();

foreach my $FileName (@DataL)
{
    my $CountReports = 0;
    my $CountRatings = 0;
    my $CountRecords = 0;
    chomp $FileName;
    my @DataI = ReadFile($FileName);
    my $LineCum = "";
    foreach my $Line (@DataI)
    {
        if ($Line =~ /\S/)
        {
            $LineCum = $LineCum . $Line;
        }
        else # here we parse the data
        {
            $CountRecords++;
            my $CountReportRatings = 0;
            @Records = split (/\n/, $LineCum);
            foreach my $Record (@Records)
            {
                if ($Record =~ /^(A|P) - /)
                {
                    $CountReportRatings++;
                }
            }
            if ($CountReportRatings > 0)
            {
                $CountReports++;
                $CountRatings += $CountReportRatings;
            }
            $LineCum = "";
        }
    }
    print "$FileName $CountRecords: $CountReports ($CountRatings)\n";
}


exit;
