
sub table_to_index {
	my ($rows) = @_;
	my $index = {};
	for (@$rows) {
		my ($ymd, $period, $resource, $who) = @$_;
		defined $who or die "bogus row in bookings data file: not enough columns\n";
		$index->{$ymd}{$period}{$resource} = $who;
	}
	return $index;
}

sub index_to_table {
	my ($index) = @_;
	my $rows = [];
	for my $ymd (sort keys %$index) {
		my $x = $index->{$ymd};
		for my $period (sort keys %$x) {
			my $x = $x->{$period};
			for my $resource (sort keys %$x) {
				my $who = $x->{$resource};
				push @$rows, [$ymd, $period, $resource, $who];
			}
		}
	}
	return $rows;
}
