Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.#!/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;
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>";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: html output to a file
by Corion (Patriarch) on Apr 27, 2007 at 16:07 UTC | |
|
Re: html output to a file
by kyle (Abbot) on Apr 27, 2007 at 16:15 UTC | |
by ww (Archbishop) on Apr 27, 2007 at 17:29 UTC | |
|
Re: html output to a file
by TomDLux (Vicar) on Apr 27, 2007 at 17:28 UTC | |
by Anonymous Monk on Apr 30, 2007 at 03:16 UTC | |
|
Re: html output to a file
by ikkon (Monk) on Apr 27, 2007 at 16:12 UTC | |
|
Re: html output to a file
by derby (Abbot) on Apr 27, 2007 at 16:53 UTC | |
|
Re: html output to a file
by glasswalk3r (Friar) on Apr 27, 2007 at 17:03 UTC |