CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help with script

 



eshipman
Deleted

Apr 10, 2000, 11:09 AM

Post #1 of 2 (273 views)
Help with script Can't Post

I have the following fields in a form:
"DatePlayed","HomeTeam","HomeInning1","HomeInning2",
"HomeInning3","HomeInning4","HomeInning5","HomeInning6",
"HomeInning7","HomeInning8","HomeInning9","HomeInning10",
"HomeRuns","HomeHits","HomeErrors","VisitTeam",
"VisitInning1","VisitInning2","VisitInning3","VisitInning4",
"VisitInning5","VisitInning6","VisitInning7","VisitInning8",
"VisitInning9","VisitInning10","VisitRuns","VisitHits",
"VisitErrors","WinningPitcher","LosingPitcher","Umpire_1",
"Umpire_2"

I read them into a hash like this:

$in;
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} else {
$in = <STDIN>;
}

$in =~ s/\+/ /g;
$in =~ s/%(..)/pack("c",hex($1))/ge;

@linescore=$in;

and store them in a file where it looks like this:
04/09/00,"Braves",0,0,1,0,2,1,0,0,0,0,4,6,1,"McLendon","Hanson","Mets",0,0,0,0,1,
0,0,0,0,0,1,4,2,"Salinsky","Lowell"

How would I determine the Winning team in this line?
Is this how???

if @linescore["HomeRuns"] gt @linescore["VisitRuns"] {
$winningteam = @linescore["HomeTeam"]
}else{
$winningteam = @linescore["VisitTeam"]
}




Jasmine
Administrator / Moderator

Apr 10, 2000, 3:24 PM

Post #2 of 2 (273 views)
Re: Help with script [In reply to] Can't Post

First, numeric comparisons use > for greater than and < for less than. gt and lt are for alphabetic comparisons. Using 5 gt 10 would say that 5 is greater than 10 because 5 is asciibetically greater than 10.

Second, array elements should be accessed by a $, not a @ ($linescore[1])

Third, arrays are stored by index number as a "flat" list of elements, and are accessed by their index number (count starts from 0), not by a name. eg. the 3rd element of @linescore should be accessed by using $linescore[2]. Hashes are accessed by key name, which can be numeric or alphabetic. So if you had a hash named %linescore, you can access the value of HomeInning2 by $linescore{"HomeInning2"}.

Fourth, are you re-reading the data from your file, or are you using the form values in $in? How are you splitting your key/value pairs? Unless you're using some really cool code and my eyes aren't working right, it looks like your form input processing is incomplete, and the results are not really being stored in a hash. Is the file writing correctly? Have you tried running the program? If so, what errors are you receiving?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives