#!/usr/bin/perl
print
"Content-type:text/html\r\n\r\n";
print "
HELLO FROM chat
";
&getFormData;
$val;
$repo;
$valo;
$hi;
$hello = 0;
%hello_rep = ();
%hello_rep = (
hello => "hello to you",
hi => "hi there",
howdy => "howdy partner",
afternoon => "is it afternoon already?"
);
#need to make match vaguer not perfect
sub finder()
{
foreach $name ($_[0]) {
if (exists $hello_rep{$_[0]}) {
return $hello_rep{$_[0]};
} else {
return "im a default resopnse"; #should call a default function
}
}
}
###################################################
print "Hello from Kenley:
";
$val = "$request{'make'}";
$hello = "$request{'hiddenfield'}";
print "Boolean: $request{'hiddenfield'}";
print "
\n";
print ": $request{'make'}";
print "
\n";
$valo = &finder($val);
if ($val =~ /hello|hi|howdy|yo/i) #multiple match does work
{
print "multiple match found welcome";
#maybe then call a hash table randomly?
}
if (($val =~ m/hello/i)&& ($hello < 1)) #multiple match doesnt seem to work GRRR
{
$repo = " hello to you";
$hello++;
}
elsif (($val =~ m/hello/i)&& ($hello >0) )
{
$repo = "you are repeating yourself";
}
elsif ((!$val =~ m/hello/i) or (!$hello) ) #or was crucial to making it work
{
$repo = "why not say hello?";
}
print $hello;
print << "DOC";
DOC
sub getFormData {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n/ /g;
$request{$name} = $value;
}
}