Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: saving cgi output as html

by katgirl (Hermit)
on May 30, 2003 at 12:59 UTC ( #261841=note: print w/replies, xml ) Need Help??

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"); } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://261841]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2016-10-24 14:45 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (307 votes). Check out past polls.