#!/s/std/bin/perl
require "perl4cgi.pl";

&PrintHeader("Emergency Vegetables");
if (&GetInput) # ok, they've clicked on the button to reset
{
    open (META, ">>metabegas.cnt") # open meta for append
	|| die "Can't open $rfile $!";
    open (COUNT, ">begas.cnt")   # and the regular file for overwrite
	|| die "Can't open $rfile $!";
    $rnum = 0;
    print COUNT $rnum;
    print META "Someone from $ENV{'REMOTE_HOST'} pushed the magic button!\n";
    close META;
    close COUNT;
}
else
{
    open (COUNT, "begas.cnt")
	|| die "Can't open $rfile $!";
    $rnum = <COUNT>;
    close COUNT;
}

print "<body> <h1> Rutabaga Alert Hotline </h1>";
if ($rnum == 0)
{
    print '<p>There are no rutabagas here.<p>';
}
else
{
    if ($rnum == 1)
    {
	print '<p>There is a single, innocent, rutabaga here.<p>';
    }
    else
    {
	print '<p>There are ', $rnum, ' rutabagas here, snarling viciously
           at you.<p>';
    }
}

open (COUNT, ">begas.cnt");

print 'Suddenly, you\'re eaten by a';
if ($rnum == 0)
{
    print 'n invisible rutabaga.<p>';
}
elsif ($rnum == 1)
{
    print 'n invisible twin of a good-tempered rutabaga.<p>';
}
else
{
    print ' rabid rutabaga.<p>';
}


$rnum = $rnum + 1;            # increment rnum by 1
print COUNT $rnum;
close COUNT;
print "Now <a href=\"grain.cgi\">go away</a>.   ";
print "(or <a href=\"third.cgi\">stay</a>)<P>";
print "<FORM ACTION=\"third.cgi\" METHOD=\"POST\">";
print "<INPUT TYPE=\"hidden\" NAME=\"albert\" VALUE=\"Yes\">";
print "If you want to reset the counter, click here: ";
print "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Die, Rutabagas!\">";
print "</FORM> </body> </html>";


