I enjoy at least trying to redo these things (whether or not the result is more or less maintainable/elegant is another question). My effort (which I know is probably something like what you already tried):
{ ## main loop show_cache_and_exit("current") if cache_is_good(); unless (cache_is_stale()) { ## cache is dead update_cache(),show_cache_and_exit("current") if i_am_the_writer(); ## we cannot do anything about a bad cache, so retry close_cache(); sleep 5; redo; } ## If I'm not the writer then show old cache show_cache_and_exit("stale") unless i_am_the_writer(); ## If I cannot fork it's up to me update_cache(),show_cache_and_exit("current") unless i_can_fork(); show_cache_and_exit("stale") if i_am_the_parent(); ## child does: be_a_child(); update_cache(); exit 0; }

In reply to RE: On elegant coding... by runrig
in thread Just thinking ... by toadi

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.