package Trbot;

use Exporter;
@ISA=(Exporter);
@EXPORT=qw(&flame);

sub flame {
my %attr = %{$_[0]};				#dereference the argument to an HASH list
@adj = @noun = @pref = @verb = @msg =();	#initialse

#print values (%attr), "-\n";
#print $attr{Templ},"------\n";

							#get the list of prefixes;
open (FILE, $attr{Prefs}); 
my $ii=0; 
while (<FILE>) {
	chomp $_;
#print $_,"\n";
	$pref[$ii++]=$_;
	}
close (FILE);
							#get the list of nouns;

open (FILE, $attr{Nouns});
$ii=0; 
while (<FILE>) {
	chomp $_;
#print $_,"\n";
	$noun[$ii++]=$_;
	}
close (FILE);
							#get the list of adjectives;
open (FILE, $attr{Adj}) ;
$ii=0; 
while (<FILE>) {
	chomp $_;
#print $_,"\n";
	$adj[$ii++]=$_;
	}
close (FILE);

opendir(DIR, $attr{Templ}) ;
@file  = grep  { !/^\./ } readdir(DIR);	#get the files in this directory
$templ = $file[int (rand $#file +1)];	#choose a random file
$file = $attr{Templ}."\\".$templ,"\n";
closedir DIR;

open (FILE, $file) or die;
while (<FILE>) {
	while ($_ =~ /<a>/) {
		s/<a>/$adj[int (rand $#adj +1)]/
		};
	while ($_ =~ /<n>/) {
		s/<n>/$noun[int (rand $#noun+1)]/
		};
	while ($_ =~ /<p>/) {
		s/<p>/$pref[int (rand $#pref +1)]/
		};
	push @msg, ($_);
	}
return @msg;
}
1;