A couple of suggestions:

First, use strict; at the top of the module will keep you out of a lot of trouble.

Next, use CGI; and using it to parse URLs and forms will keep you out of even more trouble. "As simple as possible" is not a good argument. The code you provided would be shorter if you used CGI. (If you're worried about performance, consider CGI::Lite.) In this case, never mind.

Next, if you're running a current (or nearly current) Perl distribution, the date manipulation routines you need should be included, saving you the trouble of lugging around custom methods of uncertain ancestry.

Try something like the following fragment:

use HTTP::Date qw(time2str); my $now = time2str($filetime); my $expires = time2str($filetime + $delta); print "Last-modified: $now\n"; print "Expires: $expires\n";
Finally, one of the subtle problems you'll have is that getting expire times to work depends on a couple of things that might be out of your control.

Treat setting the Expires header as an optimization, and be prepared to have it ignored.


In reply to Re: Trouble Caching an Image by dws
in thread Trouble Caching an Image by Baz

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.