View Single Post
  #1 (permalink)  
Old 03-11-2005, 08:39 PM
GregGaub GregGaub is offline
Registered User
 
Join Date: Mar 2005
Posts: 2
Unhappy Newb needs help with parsing an array into html output

All I want to do is take a single input from a form, which will probably be a very long string with values separated by commas or line breaks, presumably split that string into an array of values, then drop in those values in the appropriate places in an HTML formatted output to the browser. I've done this with individual form field inputs, but I've never worked with arrays, so I'm certain that's where my script is dying. I can't telnet into my account and run the script from the command line, but I did direct the error to the browser and it's having compilation errors (how helpful). I'll include my code below, but I'm sure it's just my basic lack of understanding how to work with arrays. Being a complete newb to this, I'd like replied to include actual code snippets that I can copy and paste, rather than "oh, just split the array and then reassign the values to a list" or some other greek to this geek. What's the key ingredient(s) that I'm obviously missing?

Thanks!
-Greg

Code:
#!/usr/bin/perl
use CGI::Carp qw( fatalsToBrowser );
open (STDERR, ">&STDOUT");

# Receive Info
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Process Info

@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;
	$value =~ s/<([^>]|\n)*>//g;
	$INPUT{$name} = $value;
}

$exportedscores = $input{'exportedscores'};

# split the input into an array
@scoredata = split(/\n/, $exportedscores);

#Show user the Scoresheet...
print <<EOM;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>ALTC Game Score: </title></head>
<LINK REL=StyleSheet HREF="/ltag/scoresheets.css" TYPE="text/css" TITLE="Preferred Style"></HEAD>
<body>

<P>
Overall game score: @scoredata[1]<BR>
Player 1 Score: @scoredata[5]<BR>
Team 1 Rank: @scoredata[7]<BR>
</P>

</body>
</html>

EOM
exit;
}
Reply With Quote