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

I was modifying Lincoln Stein's "CGI and frames" example script when I got bogged down with this bug. The script is below in its entirety. When it runs it loads the nav bar page in the topFrame (no problems there) and then loads mainFrame based on the parameter 'content'. This wasn't happeneing so I added "start" and "finish" print statements to the sub, and "start" got printed and that was it. So I added a if/else check to see if @bot_file (the product of a file slurp) was defined and that test never executes. I have been calling the script like so: http://www.thesite.com/cgi-bin/redirect.pl?content=/path/info/here/ and my "starting to open $content" appeared to have $content undef so I added
my $content = $q->param( 'content' ); if (!$content){ print $q->header,"no damn content"; exit; }
right under the $content variable assignment and the dang thing came back undef but what is more the script somehow printed the frameset and gave me the "no damn content" message in both frames!! I am so baffled. Any advice heartily welcomed!!
TIA
jg
edited by boo_radley : added readmore
#!/usr/local/bin/perl -w use strict; use CGI; my $q = new CGI; my $path_to_top = "/home/somesite/www/site/main_frame_top3.html"; my $content = $q->param( 'content' ); my $TITLE="Welcome to New Orleans"; my @top_file; my $script_name; my $path_info = $q->path_info; print $q->header; # If no path information is provided, then we create # a side-by-side frame set if (!$path_info) { &print_frameset; exit 0; } &print_html_header; &print_top if $path_info=~/top/; &print_mainframe if $path_info=~/main/; &print_end; # Create the frameset sub print_frameset { $script_name = $q->script_name; print <<EOF; <html><head><title>$TITLE</title></head> <frameset rows="147,*" frameborder="NO" border="0" framespacing="0" co +ls="*"> <frame src="$script_name/top" scrolling="NO" name="topFrame"> <frame src="$script_name/main" name="mainFrame"> </frameset> EOF ; exit 0; } sub print_html_header { print $q->start_html($TITLE); } sub print_end { print $q->end_html; } sub print_top { open (FH, "$path_to_top") or die "where's the damn file? : $!"; @top_file = <FH>; close FH; print @top_file; } sub print_mainframe { print "starting to open $content"; open (OH, "$content") or die "where's the damn file? : $!"; my @bot_file = <OH>; close OH; if (!@bot_file) { print "empty array! whassup wi'dat?"; exit; } else { print "the array is @bot_file!"; exit; } print @bot_file; print "finish"; }
_____________________________________________________
Think a race on a horse on a ball with a fish! TG

Replies are listed 'Best First'.
Re: Why is this param undefined? and Why isn't exit stopping the script from running?
by Kanji (Parson) on Mar 28, 2002 at 19:56 UTC
    Why is this param undefined?

    When you create the frameset, neither of the frames within has the original query string included in their URLs.

    Why isn't exit stopping the script from running?

    It is, but you seem to be missing a key concept about the web and frames: each frames is a seperate instance, so you're actually calling your script three times, and it's the latter two (where you've unintentionally stripped the params) that exit is stopping.

        --k.


      Thanks for the reply. I realize that
      <frame src="$script_name/top" scrolling="NO" name="topFrame"> <frame src="$script_name/main" name="mainFrame">
      instantiates 2 copies of the script, but I thought the if (!$content) {exit;} would kill process #1 before it had child processes. This is not the case?? Why?
      TIA
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG

        Ah, but the frames are second and third in the chain.

        The first link is the frameset builder, where !$content evaluates as false because $content is set if you're using the URL you mention in your original post.

        Propagating the query string so that it's set in the children frames is an easy fix, though ...

        sub print_frameset { $script_name = $q->script_name; $query_string = $q->query_string; print <<EOF; <html><head><title>$TITLE</title></head> <frameset rows="147,*" frameborder="NO" border="0" framespacing="0" co +ls="*"> <frame src="$script_name/top?$query_string" scrolling="NO" name="topFr +ame"> <frame src="$script_name/main?$query_string" name="mainFrame"> </frameset> EOF ; exit 0; }

            --k.


Re: Why is this param undefined? and Why isn't exit stopping the script from running?
by RMGir (Prior) on Mar 28, 2002 at 19:48 UTC
    Have you looked in your webserver error logs?

    Usually, one look there leads to "D'oh! _That's_ what I missed", since that's where the error messages go.

    Consider doing

    use CGI::Carp qw(fatalsToBrowser);

    --
    Mike

    Edit: found where I'd seen fatalsToBrowser before...

      Carp is a good idea and I would have used it if I were throwing errors which I'm not. Thanks though.
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG
Re: Why is this param undefined? and Why isn't exit stopping the script from running?
by jerrygarciuh (Curate) on Mar 28, 2002 at 20:19 UTC
    Re_Update:Should have hit refresh more often, here I am reply to myself and Kanji already handed solution to me on silver platter!! Kanji++ -jg Old_Update: Works without issue if $content is hard coded into the path instead of defined by $q->param();
    Obviously missing something,
    jg
    _____________________________________________________
    Think a race on a horse on a ball with a fish! TG