View Full Version : Sending perl generated html page to file + on web
farmed_trees
04-25-2003, 09:10 AM
Hi,
In my perl script, did this to print to web,
#!/bin/perl -w
...
...
print <<EOT
...
html
...
EOT
How could I save the html in a file at the same time?
Thks for any help. :)
farmed_trees
chrisvmarle
04-25-2003, 03:04 PM
Change it from this:
#!/bin/perl -w
...
...
print <<EOT
...
html
...
EOT
to:
#!/bin/perl -w
...
...
$output = qq~
html
~;
print $output; # print the output to the web
open(FILE,">output.html") || die("Couldn't open output.html for writing"); # open the file for writing
print FILE $output; # write to the file
close FILE; # close the file
Mzzl, Chris
farmed_trees
04-28-2003, 03:47 AM
Hi Chris,
Thks for your reply its kind of u :)
tried out the first part of the code - printing to the web , for some reason instead of printing it on the browser it brought up a file download dialog box... following is part of the code tried,
#!/bin/perl -w
...
...
$output = qq~
html
~;
print $output; # print the output to the web
do u know what might be the reason?
meanwhile will keep trying, thks for giving me somewhere to start. :)
farmed_trees
chrisvmarle
04-28-2003, 01:54 PM
Does the HTML start with
"Content-type: text/html\n\n"?
YUPAPA
04-28-2003, 09:35 PM
#!/usr/bin/perl
use CGI;
my $cgi = new CGI;
my $output = q(
<HTML>
<HEAD><TITLE>Hello</TITLE></HEAD>
<BODY>
My Web Site
</BODY>
</HTML>
);
print $cgi->header(-type=>'text/html');
print $output;
open(FILE,">a_file.html") or die print "Fail to write web.html: $!\n";
print FILE $output;
close(FILE);
__END__
chrisvmarle
04-28-2003, 10:05 PM
It works fine on my server... :S
farmed_trees
04-29-2003, 02:38 AM
Hi Chris,
Thks for your reply, pardon me din realise need to have \n for the following
"Content-type: text/html\n\n" :)
Thks for your help Chris, appreciate it :)
farmed_trees
farmed_trees
04-29-2003, 02:42 AM
Hi YUPAPA,
Thks for your reply.:)
Got it to work with Chris' help, in any case thks for responding!:)
farmed_trees
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.