use Bastards;					#our bastards database
use Trbot;						#here we cook our texts, one system for each b.
use News;						#lookup the postings of the b. since last time
use Post;						#nuke that b. !

while () {						#we never stop !
  %aa = @{$bastards};				
  while ( ($bastard, $attr) = each %aa){ 	#for each bastard
#print $bastard,"\n";				#log him!
							#get the ns datetime, the subjects and msg_id
	($subj, $date, $msg_id) = track $attr;
	${$aa{$bastard}}{Last} = $date;	#We have all messages up to now (ns date)
	$ii = 0;
	for $item (@{$subj} ) {			#For each posting from this bastard
							#Add Re: to the subjectline if appropriate
		$rep = ($item =~ /(^\s*[Rr]e:).*/);
		if ( ! $rep ) { $item = "Re:".$item; } 
		@msg = flame $attr;		#Cook up a nice little text
							#and post it !
#print @msg;
		post $attr, $item, \@msg, $msg_id->[$ii++];
		@msg=();				#prepare a surprise for the next one!
		}
	}
							#keep the changes to the bastard database
  open (OFILE, ">bastards.pm");
  print OFILE "\$bastards = ";
  derefer ($bastards);
  close OFILE;
  print ".....\n"; 
  sleep (20);
  }
							#routine to decorticate the database
sub derefer {
my $var = @_[0];
$nn++;
if ( ref($var) eq "ARRAY") {
	my @arr = @{$var}; my $nr = $#arr;
	print OFILE "[\n";
	for (my $ii=0; $ii <= $nr; $ii++) {
		derefer ($arr[$ii]);
		print OFILE ",\n";
		}
	print OFILE "]";
	}
if ( ref($var) eq "HASH") {
	my %arr = %{$var};
	print OFILE "{";
	for my $key  (keys %arr) {
		print OFILE $key, "=> ";
		derefer ($arr{$key});
		print OFILE ",\n";
		}
	print OFILE "}\n";
	}
if ( ref($var) eq "") {
	$var =~ s/\\/\\\\/g;
	$var =~ s/\@/\\\@/g;
	$var =~ s/\"/\\"/g;
	print OFILE "\"$var\"";
	}
$nn--;
}