Forum Moderators: coopster & phranque

Message Too Old, No Replies

Trouble with conditional operators

Please help with my if then else structure!

         

herby

5:14 am on Jul 4, 2003 (gmt 0)

10+ Year Member



Hi, can anybody help me with this problem (I'm very new to perl/cgi):

I have set up a simple script which must detect the value of a parameter in a GET request and act accordingly. Now, I know this is a very basic operation and have managed to get it functioning without too much difficulty using the following:

@parameters = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@parameters) {
($varname, $value) = split(/=/,$i);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$result{$varname} = $value;
}

if ($result{'m'} eq "200 success") {
this stuff
}

else {
that stuff
}

(The blocks to be executed have further 'if' statements and 'for' loops. This would not seem to be a problem but it is not working!)

If the condition is true it works but if the condition is false it doesn't (I get 500 Internal Server error) If I remove the else section competely and the if condition is true, all is OK (i.e. syntax appears to be correct). If the else conditionn contains nothing more than a print statement i.e. print "fish"; it still fails.

Is there a limit on nested if or for statements in Perl/cgi programming? Please, can anybody help?

Thanks in advance,

Jack.

dive into perl

7:14 am on Jul 4, 2003 (gmt 0)

10+ Year Member



If the condition is true it works but if the condition is false it doesn't (I get 500 Internal Server error)

Hi herby,

What code is within the else section? does the else section have a valid print "Content-type: text/html\n\n";
to output content to the browser, as this could the 500 server error.

Plus I would advise using the CGI module to parse your GET and POST variables e.g. :-

use CGI qw/:standard/;
my $q = new CGI;
my $m = $q->param('m');

if ($m eq "200 success") {
this stuff
} else {
that stuff
}

- dip

herby

11:38 am on Jul 5, 2003 (gmt 0)

10+ Year Member



Hi Dip,

Thank you very much for your reply. I have finally resolved my problem through basically simplifying and rewriting my code (and a bit better planning) although I'm still unsure exactly what the problem was - possibly a speling mistake!).

Anyway, thanks for the tip re the CGI module. So much to learn....

Cheers

Jack.