Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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


Comment on Re: saving cgi output as html
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2014-12-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (192 votes), past polls