#/usr/bin/perl -w

# Beispiel-Lösung zu Perl-Aufgabe 1.5
# Übung Rechnernetze WS 2005/2006

use strict;

my @table = (0,0,0,0,0,0,0,0,0,0,0);
# categories: 0-9999, 10000-19999, ...

my $category;
my $totalempty = 0; # number of lines with a '-'
my $totallines = 0; # total number of lines

while (<STDIN>) 
{
	$totallines++;
	/(\d+|-)$/; 	# get the last number or the dash
	my $size = $1;	# get the token into a variable
	if ($size eq '-') { $totalempty++; }
	elsif ($size =~ /\d+/)
	{
		# calculate the correct category to put the current entry in
		$category = ($size - ($size % 10000)) / 10000;
		
		# put it into the right category
		if ( 0 <= $category && $category <= 10)
		{
			$table[$category]+=1; # add 1 to appropriate category
		}
		elsif ($category > 10) { $table[10]+=1;	}
		else { die "Unknown format." };
	}
	else { die "Unkown file size: $size." }
}

# print result

print "Auswertung mit linearer Skala$/$/";

for (my $i=0; $i<10; $i++) {
	my $anfang =  $i*10000;
	my $ende =  ($i+1)*10000 -1;
	print "$anfang - $ende\t$table[$i] $/";
}

print "      > 99999\t" . $table[10] . "$/$/";
print "Zeilen mit '-': $totalempty$/";
print "Gesamtzeilenzahl: $totallines$/";
