Hi Monks

I am new to Perl programming, so I apologise in advance if this is a dumb question, which it most probably is. I have checked the tutorials and Q and A sections, but I can't find the answer to my question.

What I want to do is modify a Perl CGI script so that the output (a load of html) is written to a file called output.htm rather than to the web browser. The reason for this is that the perl script takes a long time to run (it is doing many queries to a database), and so I want to make it a scheduled cron job.

I have used the following code:

#!/usr/bin/perl -w use CGI qw/:standard *table *Tr *td/; require "/home/httpd/cgi-bin/per +l_scripts/syb_handlers.pl"; use Sybase::DBlib; use CGI::Carp qw(fatalsToBrowser); &dbmsghandle ("message_handler"); &dberrhandle ("error_handler"); open(OUTPUTFILE, ">/home/output.htm") or die $!; # print OUTPUTFILE header; # print OUTPUTFILE start_html( -title=>'Title', ); print OUTPUTFILE (loads of lines of html resulting from the database +queries) # print end_html;
I find that unless I comment out the lines that I have commented out (relating to the header, start_html and end_html), the output won't go to the file. If I do comment the lines out, then obviously the html isn't well formed because the header is missing.

Is there an obvious way around this, or do I need to explicitly write the header to the file using a print statement such as the following?

print OUTPUTFILE "<html><head><title> TITLE </title></head>"; print OUTPUTFILE "<body>"; print OUTPUTFILE # all my html here"; print OUTPUTFILE "</body></html>";

In reply to html output to a file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.