Ok.. as asked for..the code.... and I hate to do this cause i'm gonna get
told how everything i'm doing is wrong..
from the way I lay out the code to the way I write code to the way I don't
use every damn modual under the sun....
But after 4 hours of not getting it to work I give up.
I have commented out a lot of stuff in search of the problem.
The program runs fine till it calls on the Inn.pl package in the line below
marked <<<<<<<<<<<<<<<<
if I comment it out it completes the HTML code.
when I put it back in , the program, and the HTML code just stops.
I'm gonna go have lunch and get some duct tape.....
cause I just know I'm gonna have to wrap my head lest it explode from some
of the
non-answer comments i'm gonna get.
all programs are set to chmod 755
and to those who acutally help.. thanks for your time.
Lou
MA.cgi ######################################
#!/usr/bin/perl
use strict;
use Fcntl qw(:flock);
require 'RW.pl';
require 'Inn.pl';
srand;
# Copyright 2004 Luirandir Hernsen
#declared variables
my
(%Player,$KEY,$VAL,$Data,@Data,$InputData,%InputData,@InputData,$Item,$FormI
nput,$FN);
my ($HTML);
############################################################################
####
#$STDIN=<STDIN>;
$FormInput="Name=Luinrandir&Home=Avalon&Location=Inn&Action=Work"; #templine
############################################################################
####
Semephore();
ParseInput();
#my
$PlayerFilesDir="/home/thx-1138/public_html/MysticAdventures/PlayerFiles/";
UpdateInfo();
# All vars should be set buy this point
#require "$InputData{Location}.pl";
StartHTML();
## to read from file
# @Data=RWP::ReadFile(FileName);
# Assign array to propper game Hash
#
## to write hash to file
# RWP::WriteHash(FileName,KEYS,VALS);
close SEMEPHORE;
exit;
sub StartHTML
{
print qq|Content-type: text/html\n\n|;
print qq|<HEAD><title>$Player{Location}</title></HEAD>|;
print qq|<body bgcolor="black" text="white">|;
print qq|<TABLE WIDTH=100% HEIGHT=100% CELLPADDING=10 CELLSPACING=0
BORDER=0>|;
print qq|<TR><TD VALIGN=TOP WIDTH=75%>|;
print qq|<table BORDER=0><td width=50% valign=top><FONT SIZE=+1>|;
## this code calls on the package ###################################
print qq|-$Player{Location}-<BR>-$Player{Action}-<BR>|;
print qq|$Player{Amethyst}|;
# my $glob = $main::Inn::Work; #
# my $glob = $main::{$Player{Location} . "::"}{$Player{Action}}; #
# $glob->();
$Inn::Work(); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#####################################################################
## Options();
print qq|</TD><TD VALIGN=TOP WIDTH=50%>|;
## Box2();
print qq|</td></tr></table>|;
# #####################################################################
## TownMove();
print qq|</td><td width=25%>|;
## Stats();
print qq|</td></tr></table>END|;
}
sub Semephore
{
open (SEMEPHORE, ">Semephore.sem")
||RW::Error ("Sorry, I can't open Semephore");
# flock (SEMEPHORE,LOCK_EX);
}
sub ParseInput
{
# read(STDIN,$FormInput,$ENV{'CONTENT_LENGTH'}); #"post"
@InputData = split ( /&/, $FormInput );
foreach $Data(@InputData)
{
$Data =~ tr/+/ /;
$Data =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# $Data =~ tr/A-Z,a-z,0-9,À-ÿ//c;
# $Data =~ tr/\0//d;
}
}
sub UpdateInfo
{
#turn @IputData into player hash
foreach $Data(@InputData)
{
($KEY,$VAL) = split ( /=/, $Data );
$InputData{$KEY}=$VAL;
}
# read player file and parse into hash
@Data=RW::ReadFile("$InputData{Name}-$InputData{Home}.pf");
foreach $Data(@Data)
{
($KEY,$VAL) = split ( /=/, $Data );
$Player{$KEY}=$VAL;
}
# update player info
foreach $Data(@InputData)
{
($KEY,$VAL) = split ( /=/, $Data );
$Player{$KEY}=$VAL;
}
# RW::WriteHash();
# player info load into hash and updated by this point
}
###############################
Inn.pl #########################
##############################
package Inn;
Buy
{}
Sell
{}
Talk
{}
Sleep
{}
Delivery
{}
Work
{
# GameTime(.1);
# SendOff();
print qq|"Well afraid I do all my own work Try another business"|;
}
Movement
{
if ($GameTime>23 or $GameTime<6)
{
## GameTime(.1);
print qq| The Inn Keeper comes out of the back room|;
print qq|holding a candle in one hand and a sword in the other.|;
print qq|"Who comes here at this last hour...|;
print qq|a room will cost you double!"<BR>|;
}
else
{
print qq|You have arrived during business hours.|;
## GameTime(.1);Greetings();
}
}
#OptionCodes
#{
# $Buy=1;$Sell=1;$Talk=0;$Zone=0;
# $AcceptOffer=0;$Hunt=0;$Search=0;$Sleep=1;
# $ViewMap=1;$Offering=0;$Speech=0;$Attack=0;$Repair=0;
# $Tax=0;$Supplies=0;
# if ($Player{Title} eq "Lord" || $Player{Title} eq "Lady"){$Work=0;}else
{$Work=0;}
# if ($Player{Religion} < 0 ){$Pray=1};
# if ($Player{Religion} > 0 ){$Magick=1;}
# if ($Player{Alignment} < 0){$HideWait=0;}
# if ($Player{Alignment} < -10){$Attack=1;}
#}
return 1; #and yes I can do this cause its a package!
#######################
RW.pl ######################
#######################
package RW;
#####
sub WriteHash #OK
{
#[0]=FileName : [EMAIL PROTECTED] : [EMAIL PROTECTED]
# Example of the code to access
# Convert Hash to two Arrays
#
#
# RWP::WriteHash(FileName,KEYS,VALS);
#if file does not exist, make it.
if (-e $_[0] == "0")
{
open (WH,">$_[0]");
flock (WH,LOCK_EX);
chmod (0755,$_[0]);
close (WH);
}
@KEY=split/ /,"$_[1]";
@VAL=split/ /,"$_[2]";
open (WH,">$_[0]");
flock (WH,LOCK_EX);
$V=0;foreach $KEY(@KEY)
{
$Data[$V] = "$KEY=$VAL[$V]";
$V++;
}
@Data = sort {$a cmp $b}(@Data);
foreach $Data(@Data)
{
print WH $Data;
}
close (WH);
}
sub ReadFile
{
open (RH, "$_[0]")||Error("ReadFile - Sorry, I can't open $_[0]:<BR> $!
");
# flock (RH,LOCK_EX);
@Data =<RH>;
close (RH);
return @Data;
}
sub ConvertFile #need to check
{
if (-e $_[0])
{
open (RH, "$_[0]");
flock (RH,LOCK_EX);
@Data =<RH>;
close (RH);
}
open (WRITE, ">$_[0]")||Error("Can't write to $_[0]");
flock (WRITE,2);
chmod(0666,$_[0])||Error ("Sorry, I can't change chmod on $_[0]");
for ($v1=0;$v1<"131";$v1++)
{
$PlayerFile{$VarList[$v1]}=$Data[$v1];
}
while (($VarList,$Data) = each (%PlayerFile))
{
$array[$v1]="$VarList=$Data\n";
$v1++;
}
@array=sort(@array);
print WRITE @array;
close (WRITE);
}
sub Error
{
print qq|Content-type: text/html\n\n|;
print qq|<HEAD><title>ERROR</title></HEAD>|;
print qq|<body bgcolor="red" text="black">|;
print "<CENTER><H3>:Error:</H3><BR>";
print "<H3>$_[0]</H3></CENTER>";
print qq|</BODY></HTML>|;
# exit;
}
return 1;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>