http://www.perlmonks.org?node_id=261841


in reply to saving cgi output as html

What arthas said, except you may want to change the name of the file if the data is different each time and you want to keep it. Like so:
my $filename = time(); my $doc = ''; open (MYOUT, ">/mypath/$filename.html") or die $!; $doc .= "<p>Mydata....</p>"; $doc .= "<p>Myotherdata....</p>"; print $doc; # This goes to the web browser print MYOUT $doc; # This goes to a files close (MYOUT);
You may also want to add a piece of code to clear out the old files after a specified number of days:
my(@files, $file); opendir(DATADIR, "datadir"); @files = grep(/[0-9].html/,readdir(DATADIR)); closedir(DATADIR); foreach $file (@files) { if (-M "data/$file" > 30) { unlink("data/$file"); } }