sybperl-l Archive
Up Prev Next
From: jdolan at c3i dot saic dot com (Jim Dolan)
Subject: Help with rogue Perl script!!
Date: Nov 27 1995 10:45PM
HELP!!!
This is mostly a problem with just plain perl (4.036) not the sybperl
extensions, but I'm getting desperate.
I've been working on this bloody thing for two days. It's got to be
something so simple I'm going to look like an idiot, but I can't find it.
This is a perl script for a cgi-bin back end. The QUERY_STRING that is
passed to it is:
QUERY_STRING "savefile=my+test&Query=act_option%3DSave%26tab_producer%3Don"
The request method is GET.
If I don't pass in a savefile to it ("savefile=&Query=..."), the default
filename 'ScratchQuery.tmp' is used and the file is opened. But if I actually
have a savefile name, nothing happens!! I can run this from a terminal window
by manually setting the QUERY_STRING env variable and it works perfect, but as
soon as I try it from any WWW client, it gets to the open and just stops, none
of the print statements after that are executed even the die isn't run!!!
I've included the sub ReadParse() from the cgi-lib.pl library.
If anyone has any ideas on this I can really use some help.
Thanks in advance,
Jim Dolan, SAIC
dolanj@cpva.saic.com
########################## Cut Here #############################
#!/usr/httpd/bin/sybperl
# saveQuery -- saves the query that the user requested
#-------------------------------------------------------
# Include perl libraries
#-------------------------------------------------------
#unshift(@INC, "$SERVER_ROOT/lib/perl"); # Perl library ( for "cgi-lib.pl" )
#require "cgi-lib.pl";
$ENV{'FIVED_QUERY_HOME'} = "/usr/httpd/web_queries";
$query_dir = $ENV{'FIVED_QUERY_HOME'};
print "Content-Type: text/html\n\n";
&ReadParse();
$Fetchqry = $in{fetchqry};
$Savefile = $in{savefile};
$Query = $in{Query};
#debugging code
print "doing the save\n";
print "fetchqry = |$Fetchqry|\n";
print "savefile = |$Savefile|\n";
print "Query = |$Query|\n\n \n";
# Determine the filename. Use (in order) savefile, fetchqry, or default name
if ($Savefile)
{
$outfile = $Savefile;
}
elsif ($Fetchqry)
{
$outfile = $Fetchqry;
}
else
{
$outfile = "ScratchQuery.tmp";
}
# Change any spaces to underscores
$outfile =~ s/ /_/g;
print "|$outfile| \n ";
open (OutFile, ">$query_dir/$outfile) || die "Can't save file $outfile.";
print OutFile $Query;
close OutFile;
print " ";
print "Your query was saved as $outfile. \n";
print 'To return to Target Query, Press the Back button twice.';
print ' Or ';
print '';
print 'Begin a New Query';
sub ReadParse {
if (@_) {
local (*in) = @_;
}
local ($i, $loc, $key, $val);
# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
$in .= getc;
}
}
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Convert %XX from hex numbers to alphanumeric
$in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
# Split into key and value.
$loc = index($in[$i],"=");
$key = substr($in[$i],0,$loc);
$val = substr($in[$i],$loc+1);
$in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
return 1; # just for fun
}
__END__;
------ End of Forwarded Article
|