﻿if (@ARGV < 1) { # 명령어 라인 매개변수 검사
	die "Usage: perl getStatistics.pl inputfile.txt\n";
}
open (INFILE, $ARGV[0]) || die "Can't open input file\n";
%words       = ();
$total_words = 0;
while ($line = <INFILE>) {
	# next if ($line !~ s/^\s*<[pl]>(.+)<\/[pl]>\s*$/$1/); # <p>...</p>
	$line =~ s/^\s+|\s+$//g;
	$line =~ s/  +/ /g;
	@tokens = split(/ /, $line);
	$total_words += @tokens;
	foreach $token (@tokens) {
		$words{lc $token}++;
	}
}
close (INFILE);
# 고빈도순으로 누적빈도 비율과 함께 어절 목록 출력
$acc_type = $acc_freq = 0;
$total_types = scalar(keys %words);
foreach $word (sort {$words{$b}<=>$words{$a}} keys %words) {
	$acc_freq += $words{$word};
	$acc_100 = $acc_freq/$total_words * 100;
	print $word, "\t", $words{$word}, "\t";
	printf("%.2f\t%.2f\n", ++$acc_type/$total_types, $acc_100);
}
