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

the program is not outputting the contents of the frame.txt file, though it is properly outputting the contents of the file local_frame_left.txt and the file frame_bottom.txt. what could be the reason to this... heres my code:
#!/usr/bin/perl print "content-type:text/html\n\n"; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use warnings; my $step =param(step); print<<html1; <html> <head> <title>Register online</title> </head> <body style="background-color:#BC9FAC;"> <br><br> html1 open(frame,'/home/www/xxxxxxxxxxxxxxxxx.com/frame.txt') or die "error +is: $!"; while(<frame>) { print "$_\n"; } close(frame); print<<html2; <br><br> <center> <div style="margin:0 auto;width:750px;height:420px;"> html2 open(frame_left,'/home/www/xxxxxxxxxxxxxxxxxxxxxx.org/local_frame_left +.txt') or die "error is $!"; while(<frame_left>) { print "$_\n"; } close(frame_left); print<<html3; <div style="width:534px; height:400px;float:right"> <form method="post" action="http://xxxxxxxxxxxxxxx.org +/cgi-bin/local.cgi"> html3 print<<htmlx; Give me details for my Area : <select name="area"> <option value='abc'>abc <option value='def'>def </select> <input type="hidden" name="step" value="2"> <input type="submit" value="Go"> </form> </div> </div> </center> htmlx open(frame_bottom,'/home/www/xxxxxxxxxxxxxx.org/frame_bottom.txt'); while(<frame_bottom>) { print"$_\n"; } close(frame_bottom); print<<htmlx2; </body> htmlx2

Replies are listed 'Best First'.
Re: why is the content of frame.txt file not displaying
by Corion (Patriarch) on Jun 23, 2008 at 13:43 UTC
Re: why is the content of frame.txt file not displaying
by pc88mxer (Vicar) on Jun 23, 2008 at 13:51 UTC
    I would factor your code -- it can actually help you debug the problem. Define a subroutine like this:
    sub insert_file { my $file = shift; my $path = "/home/www/artoflivingdelhi.org/$file"; unless (open(F, "<", $path)) { warn "insert_file: open of $path failed: $!"; print "<!-- insert_file: open of $path failed: $! -->\n"; } else { while (<F>) { print $_, "\n"; } # just copying what you have close(F); } }
    Then you can use it like this:
    use strict; use warnings; use CGI qw(:standard); ... print header(); ... insert_file("frame.txt"); ... insert_file("local_frame_left.txt"); ...
    With all of your files being inserted by the same code, you'll find bugs much more quickly. Doing just this might fix your current problem, and if no files get inserted, then you know the problem is in the insert_file routine.
Re: why is the content of frame.txt file not displaying
by ww (Archbishop) on Jun 24, 2008 at 01:55 UTC

    Most of the problems you've encountered regarding this project were well answered in the thread begun with your previous post, Problem printing contents of file.

    So, please step back and review the responses previously provided - as a courtesy to PerlMonks... and for the wisdom you'll perhaps be able to absorb with somewhat more diligent effort.

    By way of reminder of the information in some of those replies, note that when this code is checked (ie, perl -c scriptname) without "use strict; use warnings" the output is:

    perl -c 693525.pl [Mon Jun 23 21:24:06 2008] 693525.pl: Unquoted string "step" may clash + with future reserved word at 693525.pl line 12. 693525.pl syntax OK

    and with strict and warnings, this ensues:

    ~$ perl -c 693525.pl Content-type: text/html <h1>Software error:</h1> <pre>Bareword &quot;step&quot; not allowed while &quot;strict subs&quo +t; in use at 693525.pl line 12. 693525.pl had compilation errors. </pre> <p> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. </p> [Mon Jun 23 21:24:48 2008] 693525.pl: Bareword "step" not allowed whil +e "strict subs" in use at 693525.pl line 12. [Mon Jun 23 21:24:48 2008] 693525.pl: 693525.pl had compilation errors +.

    Please consider adopting a personal policy of using strict and warnings until you are far more expert with perl... and -- if you absolutely must and know why you're doing so-- turn off the relevant strictures. Again, the previous thread offers several notes on this, the essence of which is that you should consider "strict" and "warnings" tools to help you write working code; not as some kind of punishment or penalty.

      my computer is behaving nuts!... see what its doing.. i prints the file frame.txt for the code:
      open(fhrame,$filename) or die "Couldnt open '$filename': $!"; while(<fhrame>) { print "$_\n"; }
      but it refuses to print the file for the code:
      open(frame,$filename) or die "Couldnt open '$filename': $!"; while(<frame>) { print "$_\n"; }
      the diffrence in the 2 sets of code is fhrame is replaced by frame. thats all. Can anyone ever give a logical explanation to this weird phenomena? or it seems there could be some prob with the word frame. maybe its a keyword or something.. what say?
        Unlikely story.
        use strict;
        use warnings;
        use UPPERCASE for filehandles (thats the convention)
        make sure the file is not empty