#! /usr/bin/env perl
# $Id: topic2single.pl 1869 2008-01-07 20:42:26Z jnieuwen $
# Reads files with topic change emails from dirs.
# So something like:
# find <path> -type f | ./topic2single.pl

use strict ;
use warnings ;

while (my $file = <STDIN>) {
	chomp $file ;
	if ( -e $file ) {
		open FILE,$file or next ;
		while (my $line = <FILE>) {
			chomp $line ;
			if ($line =~ /([^ ]*) changed topic of ([^ ]*) to: (.*)/) {
				my $nick = $1 ;
				my $channel = $2 ;
				my $topic = $3 ;
				foreach my $subtopic (split(/\|+/,$topic)) {
					$subtopic =~ s/^[ ]*// ;
					$subtopic =~ s/[ ]*$// ;
					print "$channel: $subtopic\n" ;
				}
			}
		}
		close FILE ;
		# unlink $file ; Uit voor de eerste debug run on hermod. TODO enable.
	}
}

