Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic problem I don't get!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
can anyone please tell me what is wrong with this script? I have staired at it for more than an hour and it looks like it sould work to me, but when I go to the page it will only direct me to the "one" page and not any of the other pages when I select "two" or "three"


#!/usr/bin/perl

#print "Content-type:text/html\n\n";

read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@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;
$FORM{$get_page}=$value;
}

#require "cgi-lib.cgi";
#&ReadParse(*input);
#$uname= $input{'get_page'};

if ($get_page eq "one") {
print "Location:}
elsif ($get_page eq "two") {
print "Location:}
else {
print "Location:}
 
two possible causes:
you should predeclare %FORM outside of the foreach loop, or it will only be available inside of it (i probably wrong about the necessity of this one, but am used to stricter coding rules than normal cgi's).
in the foreach loop, you should say '$FORM{$name} ...' instead of '$FORM{$get_page} ...'. this is the spot that's probably the cause. when it sets the value, it's setting it to the entry in %FORM keyed by the value of $get_page(which is nothing at this point), and NOT setting it to $get_page. i'm not quite sure, because if this is the case, it would have always defaulted to case 'three', which you say it didn't. in any case, i made the if conditions stricter as well to prevent that particular happenstance. now, for the 'if' conditionals at the bottom, you'll need to say 'if ($FORM{get_page} eq 'one')'.
so, here's what the main part will look like:[tt]

read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
%FORM = ();
@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;
$FORM{$name}=$value;
}

if ($FORM{get_page} eq "one") {
print "Location:}
elsif ($FORM{get_page} eq "two") {
print "Location:}
elsif ($FORM{get_page} eq "three") {
print "Location:}
[/tt]

next time this happens, try using 'perl -w' and you'll get warning messages that may lead you to finding the problem. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top