#!/usr/bin/perl

    # First open my database.  Complain if unable.

open(STUFF, "stuff") || die "Can't open stuff: $!\n";

    # Load inverted array.

while (<STUFF>) {

    # Split the record into its fields.

    ($beastie, $noses, $hazard, $premium, $servants)
	= split(/:/, $_);

    # Append to current list.  (Note .= assignment operator.)

    $beastie_list{$hazard} .= $beastie . ",";
}

    # Now print the inverted entries out.

foreach $hazard (sort keys(%beastie_list)) {
    chop($beastie_list{$hazard});         # Delete final space.
    print $hazard;
    print " " x (16 - length($hazard));   # "tab" to column 16.
    print $beastie_list{$hazard}, "\n";
}
