#!/usr/bin/perl

use Env qw(HOME);

open(FILE,"$HOME/hours") or die "$!";

$wktot = 0;

while (<FILE>) {
	if ((length $_) > 1){

		($day) = /^(\w+):/;
		@times = /(\d+:\d+)\s*-\s*(\d+:\d+)/g;

		$tot = 0;

		for ($i=0; $i < $#times; $i+=2) {
			# Perl5.5 way
			#($h1,$m1) = ($times[$i+1] =~ /(\d+):(\d+)/);
			#($h2,$m2) = ($times[$i] =~ /(\d+):(\d+)/);
			#$tot += ($h1+($m1/60))-($h2+($m2/60));

			# Perl5.8 way
			$times[$i+1] =~ /(\d+)(?{$h1 = $^N}):(\d+)(?{$h1 += $^N\/60})/;
			$times[$i] =~ /(\d+)(?{$h2 = $^N}):(\d+)(?{$h2 += $^N\/60})/;
			$tot += $h1-$h2;
		}

		print "$day : $tot\n";
		$wktot += $tot;
	}
	else {
		print "Week total: $wktot\n";
		$wktot = 0;
	}
}

close(FILE);

exit;

