For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > September 2005 > Yet another package problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Yet another package problem
Luinrandir

2005-09-16, 6:55 pm

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,$InputDat
a,%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_LENG
TH'}); #"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 : [1]=@KEY : [2]=@VAL
# 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;


Bob Showalter

2005-09-16, 6:55 pm

Luinrandir wrote:
> ###############################
> 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"|;
> }
> ...


Did you forget "sub" keywords on each of these?


Ovid

2005-09-16, 6:55 pm

--- Luinrandir <Luinrandir@insight.rr.com> wrote:
> 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....


With all due respect, starting an email with what other's might view as
hostility is a rough way of asking for help. Many of the folks here
are not just saying "change X to Y and it will work." They're also
interested in helping people become better programmers. I am very
passionate about Perl and I must confess that I want newer Perl
programmers to be better. As more good Perl code is produced, it can
only help the reputation of the language and of Perl programmers in
general.

I will say that there are numerous bugs in your code but since you have
made it clear you do not want more general assistance, I will honor
your request.

> But after 4 hours of not getting it to work I give up.


This is not a coincidence.

You may view this email as a flame, but I hope you don't. It's not my
intention to offend. If you ever want more general advice about making
your programs more robust, please don't hesitate to ask.

Cheers,
Ovid

--
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com