So I've got two related problems in one script here, and I'm hoping for some suggestions on either coding or algorithm.
What I'm doing now:
The script is called as a cgi script, expected to output data from a production environment and cache that output so-as not to tax the sql server everytime the output is requested. Thus far, I've been choosing to re-write an html file containing the output, then open said file and print it to stdout, or simply open the file and print it, (decision is based on algorithms of time and data not relevant to this posting).
The first problem:
When I refresh the data by overwritting the 'cache' file, I am effectively printing each line to the file, closing the file, re-opening it, and printing each line again. Is there not a way to redirect STDOUT to BOTH a file and STDOUT at the same time? - in effect cancelling the need to re-open and reiterate through the file just to print it?
The second problem:
Is there a more efficient way to output the file to stdout, ie: cat function? I'm basically doing this:
my $filename = "/cache/some/file.html";
open(OUT,$filename) || errout();
while(<OUT>) { print ; }
close(OUT);
Any ideas, thoughts, comments, or suggestions greatly appreciated. This is a trial-run before I look to writting a slightly more complicated Perl handler in mod_perl to do the same job for a whole bunch of scripts, (where it will ideally redirect the stdout of a given script to the cache if need be, and find the cached output and dump it). For now I'm trying to KISS (keep it simple, stupid) - just to prove the concept.
Thanks.