[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Script problems



Hello all:

I'm still having problems with a short "form input script".  I'm trying to
dump the user form input into a local file.  My setup is Netscape v1.1, a
powermac, MacPerl 5.03, and the following script code:

#!perl
#
# target.acgi...a script that provides a gateway to fill a
# file with user "target form" input.
#
# copyright (c) Steve Goodwin, January 1996
#
# this script uses two subroutines from Sandra Silcot's port of Steven
Brenner's cgi-lib.pl
# library,
# i.e. "cgi-lib-mac.pl".

&ReadParse(*input);
&Setup_Header;

print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Targets</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "\n";
print "<H1>Thanks for the new information.</H1>";
foreach $key (sort(keys(%input))){
  print "$key = \"$input{$key}\"\n";
}
print "\n\n";

# now input form data to file

open(DALLAS,">>Power HD:Desktop Folder:dump.txt");
foreach $key (sort(keys(%input))){
     print DALLAS "$key = \"$input{$key}\"\n";
}
print DALLAS "abcdefg\n"; # test data to make sure something is geting to
dump.txt
close(DALLAS);

#footer of HTML response

print "</BODY>\n";
print "</HTML>\n";

############################################################################
########
#   subroutines
############################################################################
########

sub ReadParse {
  if (@_){
    local (*in) = @_;
  }

local ($i, $key, $val);

  # Read in text from STDIN (i.e. user form input)
  if ($ENV{'REQUEST_METHOD'} eq "POST"){
    read(STDIN,$in,$ENV{'CONTENT_LENGTH});
  }

@in = split(/&/,$in);

  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Split into key and value.  line 62!

    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =

    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;

    # Associate key and value
    $in{$key} .= "\O" if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
  }
}

# Setup_Header
# Returns the magic line which tells WWW that we're an HTML document
sub Setup_Header {
    local($header) = <<HTML_HEADER;
HTTP/1.0 200 OK
Server: Webstar 1.2.4
MIME-Version: 1.0
Content-type: text/html

HTML_HEADER
    # 16Sep94: HTTP Header needs CRLF, not just CR!
    $header =~ s/\015/\015\012/g;
    return ($header);
}  # line 89...


Here are errors from the debugger:

# syntax error, next token ???
File 'Power HD:Desktop Folder:WebSTARŠ:target.acgi'; Line 62
# Bare word found where operator expected, near "# Split into key"
File 'Power HD:Desktop Folder:WebSTARŠ:target.acgi'; Line 62
# Missing right bracket, at end of line
File 'Power HD:Desktop Folder:WebSTARŠ:target.acgi'; Line 90
# Power HD:Desktop Folder:WebSTARŠ:target.acgi had compilation errors.

All help is much apprecited!

Steve Goodwin
spoog@iag.net