#!/usr/local/bin/perl
#
# Placed in the public domain by Carl Hommel

;#      Keyword in telegram  output file name
%TYPE_TO_FILE = ("Product",  "tele.production",
                 "Announce", "tele.announce",
                 "BULLETIN", "tele.bulletins",
                 "Telegram", "tele.telegrams" );

# Open all the output files
foreach $handle (keys %TYPE_TO_FILE) {
    open($handle, ">>$TYPE_TO_FILE{$handle}") || die "Cannot append to \"$TYPE_TO_FILE{$handle}\": $!\n";
}

line:while (<>) {
    if (/^>/) {
        search:foreach $handle (keys %TYPE_TO_FILE) {
            next search if (!/^> $handle/);
            $output = $handle;
        }
    }
    print $output $_;
}
