J. Alejandro Ceballos Z. wrote:

I made a CGI that must send a piece of code to screen, otherwise, must return a redirect command (is a banner CGI)


What it is stange to me is that the construction:

# ....blah, blah above
#
# Returns code or redirect to the page
print ($str_codetoreturn)
   ? $cgi_this->header().$str_codetoreturn
   : $cgi_this->redirect(-uri=>$str_redirecto);
#
# end of cgi


sends a "premature end of headers" error; but:


# ....blah, blah above
#
# Returns code or redirect to the page
if ($str_codetoreturn)
  { print $cgi_this->header().$str_codetoreturn; }
else
  { print $cgi_this->redirect(-uri=>$str_redirecto); }
#
# end of cgi


works fine.

($cgi_this is my CGI object)


Why is this?

You are falling afoul of perl's precedence rules:

perldoc perlop
[snip]
       Terms and List Operators (Leftward)

       A TERM has the highest precedence in Perl.  They include variables,
       quote and quote-like operators, any expression in parentheses, and any
       function whose arguments are parenthesized.  Actually, there aren't
       really functions in this sense, just list operators and unary operators
       behaving as functions because you put parentheses around the arguments.
       These are all documented in perlfunc.

       If any list operator (print(), etc.) or any unary operator (chdir(),
       etc.)  is followed by a left parenthesis as the next token, the
       operator and arguments within parentheses are taken to be of highest
       precedence, just like a normal function call.

       In the absence of parentheses, the precedence of list operators such as
       "print", "sort", or "chmod" is either very high or very low depending
       on whether you are looking at the left side or the right side of the
       operator.


So you should write the expression without parentheses like:

# Returns code or redirect to the page
print $str_codetoreturn
   ? $cgi_this->header() . $str_codetoreturn
   : $cgi_this->redirect( -uri => $str_redirecto );
#
# end of cgi



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to