in reply to calling a html file from a perl script

There's two ways I usually do something like this:

Approach One: Use what's called a "here" document and type your HTML into the perl code, as shown below.

if ($my_condition) { print <<EOF; <HTML><HEAD><TITLE>This code is shown if it's true</TITLE> </HEAD><BODY> <H1>My_condition is TRUE</H1> </BODY></HTML> EOF } else { <HTML><HEAD><TITLE>This code is shown if it's false</TITLE> </HEAD><BODY> <H1>My_condition is FALSE</H1> </BODY></HTML> EOF

This is best used if you've got short documents.

Approach Two: Use a CGI redirect. This is if you already have the HTML docs, and just want to serve them. In this case, DO NOT USE a CGI header (i.e. the line where you'd normally print "Content-type: text/html\n\n";)

if ($mycondition) { print "Location: url_of_html_file\n\n"; } else { print "Location: url_of_another_html_file\n\n"; }

This second approach is a little quicker and probably more along the lines of what you'd want to do.

Replies are listed 'Best First'.
Re: Re: calling a html file from a perl script
by suaveant (Parson) on Jul 21, 2001 at 01:15 UTC
    the second approach is a good approach, but doesn't it require a
    print "Status: 302 Moved Temporarily\n";
    at the top. Maybe not, but I've always used it that way, and seen it that way...

                    - Ant

      Apache will notice the "Location:" and change the status to 302. Inferior web servers may require additional handholding.

      -- Randal L. Schwartz, Perl hacker