in reply to Problem with form submission and redirect

Since you've already been given the solution, I want to put in a few words on style.

First of all, you can avoid backslashitis by using the quotelike operators that let you use any character as quote terminator:

print qq!<p><input type="radio" name="type" value="admin">\n!; Better yet, if you use an opening curly, bracket, paren or such, the terminator will be a closing one: print qq{<p><input type="radio" name="type" value="admin">\n}; However, please, please avoid rows of print statements. Use here documents instead.
print <<"EOT"; Content-type: text/html <html> <head> <meta http-equiv="refresh"content="0;url=http://mail.$domain/cgi-bin/s +qwebmail"> </head> </html> EOT

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Problem with form submission and redirect
by Arcanum (Sexton) on Aug 26, 2002 at 17:05 UTC

    Thanks for the tips. I was going to use a here document, but I couldn't get it working initially. I didn't realize I needed to wrap it in quotes until I looked at an old script I wrote that made use of a here document.

    Having never had any sort of instruction in Perl, I'm not sure of the reason why rows of print statements are to be avoided. Is it simply for readability, or is there a functional advantage?

      Well, compare
      print "Content-type: text/html\n\n"; print "<html>\n"; print "<head>\n"; print "<META http-equiv=\"refresh\" content=\"0; url=http://mail.$ +domain/cgi-bin/qmailadmin\">\n"; print "</head>\n"; print "</html>\n";
      with
      print <<REDIRECT; Content-type: text/html <html> <head> <META http-equiv="refresh" content="0; url=http://mail.$domain/cgi-bin +/qmailadmin> </head> </html> REDIRECT

      I would say that the second one is more readable and more maintainable. And be sure to read merlyn's strong suggestion to use CGI.pm for this particular application, instead of the code above.

      --t. alex
      but my friends call me T.

        Use CGI redirect for cleaner code. print "Location: /mail.$domain/cgi-bin/qmailadmin\n\n"; See Merlyn's post (Randal Schwartz) above. Rather than either example below shown previously. print "Content-type: text/html\n\n"; print "<html>\n"; print "<head>\n"; print "<META http-equiv=\"refresh\" content=\"0; url=http://mail.$ +domain/cgi-bin/qmailadmin\">\n"; print "</head>\n"; print "</html>\n"; print <<REDIRECT; Content-type: text/html <html> <head> <META http-equiv="refresh" content="0; url=http://mail.$domain/cgi-bin +/qmailadmin> </head> </html> REDIRECT
        Just an observation, from a lowly peasant :) HEREDOCS seem to break up the flow when indentation is thrown in the mix..
        Compare NORMAL with a bit of creative indentation ------ sub level1{ if ($level2){ print "Content-type: text/html \n\n". "<html> \n". "<head> \n". "<META http-equiv=\"refresh\" "content=\"0; ". "url=http://mail.$+domain/cgi-bin/qmailadmin\"> \n". "</head> \n". "</html> \n"; } } with HEREDOC ------- sub level1{ if($level2){ print <<REDIRECT; Content-type: text/html <html> <head> <META http-equiv="refresh" content="0; url=http://mail.$domain/cgi-bin +/qmailadmin> </head> </html> REDIRECT } }