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

I'm trying to write a script that will serve an HTML page with two frames, each of which call itself (the script) with different parameters and output themselves into the two frames.

Is that possible?

Here's my basic attempt that didn't work (test.pl):

#! /usr/bin/perl -w use strict; use CGI qw(param); #this has the head_foot() function require "templates/standard_templates.pl"; use vars qw($head $foot); my ($head,$foot) = head_foot(); if (param("page") eq "top") { page_top(); exit; } elsif (param("page") eq "bottom") { page_bottom(); exit; } else { page_main(); } sub page_main { print <<EOF; $head <frameset rows="25,*"> <frame src="test.pl?page=top" name="frametop"> <frame src="test.pl?page=bottom" name="framebottom"> </frameset> $foot EOF } sub page_top { print <<EOF; $head <h1>TOP OF THE PAGE</h1> $foot EOF } sub page_bottom { print <<EOF: $head; <h1>THIS IS THE BOTTOM</h1> $foot EOF }

Replies are listed 'Best First'.
Re: Is if possible to fill all framesets with the same CGI?
by dvergin (Monsignor) on Apr 24, 2001 at 02:52 UTC
    melguin, your concept is fine.

    But you have a number of minor things wrong with your script which you were apparently unable to diagnose because you were not looking at the error log. So: first and foremost find out where the error log is on your server and get chummy with it. That's your life line. My response here is based on loading your code and then walking through the errors that popped up in the log one-by-one.

    The first few things were:
      - colon after EOF in page_bottom
      - no check for undefined param("page") on first call

    Here's a working revision of your code (I had to change a few things for my setup that you will want to change back):

    #!/usr/bin/perl -w use strict; use CGI qw(param); my $head = "Content-type: text/html\n\n"; $head .= "<html><head></head>\n"; my $foot = "</html>\n"; if (defined param("page")) { if (param("page") eq "top") { page_top(); exit; } elsif (param("page") eq "bottom") { page_bottom(); exit; } } else { page_main(); } sub page_main { print <<MAIN; $head <frameset rows="50,*"> <frame src="test.pl?page=top" name="frametop"> <frame src="test.pl?page=bottom" name="framebottom"> </frameset> $foot MAIN } sub page_top { print <<TOP; $head <h1>TOP OF THE PAGE</h1> $foot TOP } sub page_bottom { print <<BOTTOM; $head <h1>THIS IS THE BOTTOM</h1> $foot BOTTOM
      Thanks both to your very helpful replies. The major problem ended up being my html in the $head I got externally. However, your comments were very useful to my coding in general. Much enlightened, thanks.
Re: Is if possible to fill all framesets with the same CGI?
by dws (Chancellor) on Apr 24, 2001 at 01:47 UTC
    There's a working example of how to do this here.