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.

In reply to cat "file" functionality within Perl by Unix_Usr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.