Samn has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: redirect with CGI.pm
by blokhead (Monsignor) on Nov 21, 2002 at 17:45 UTC
    You need $referring_url to be interpolated in the new string. For that, you need double quotes:
    print redirect("$referring_url&alert=3");
    With single quotes, it leaves the string exactly how you have it: i.e, it's a string that begins with a dollar sign, not the contents of the variable. This is why your browser was being pointed to /cgi-bin/$referring_url&alert=3.

    Your first example produced a syntax error because the compiler didn't know how to interpret &alert=3 as Perl code -- you didn't have it inside any string.

    blokhead

Re: redirect with CGI.pm
by dws (Chancellor) on Nov 21, 2002 at 18:52 UTC
    I suspect you need to change
    print redirect($referring_url&variable=value); ^
    to
    print redirect($referring_url?variable=value); ^
    to get a well-formed URL.

Re: redirect with CGI.pm
by iburrell (Chaplain) on Nov 21, 2002 at 17:53 UTC
    You need to use double quotes so Perl will interpolate the variables inside the string.
    print redirect("$referring_url&alert=3");
    Single quotes mean a literal string which is exactly what you got in the second case. In the first case, Perl interprets it as perl code. This is the error I get when running the snippet:
    Operator or semicolon missing before &variable at -e line 1. Ambiguous use of & resolved as operator & at -e line 1. Can't modify bitwise and (&) in scalar assignment at -e line 1, near " +value)"
    With Perl, it you get a "500 Server Error", it means that the script died. You should look in the web server error log, or run the script from the command line, to figure out why it died.