Being a former logic programming daemon, let's take a completely different take on writing this. Among other things, this different take shows that you should use constants instead of strings to avoid spelling errors.
## main loop
if (cache_is_good()) {
show_cache_and_exit("current");
}
# INSTEAD BECOMES
cache(GOOD) && show_cache && exit('current');
if (cache_is_stale()) {
if (i_am_the_writer()) {
if (i_can_fork()) {
if (i_am_the_parent()) {
show_cache_and_exit("stale");
}
## child does:
be_a_child();
update_cache();
exit 0;
}
## cannot fork, so it's up to me
update_cache();
show_cache_and_exit("current");
}
## I'm not the writer, so show old cache
show_cache_and_exit("stale");
}
#### BECOMES
(cache(BAD) && sleep(5) && redo)
||
(cache(STALE) &&
(!i_am_writer && show_cache && exit(STALE))
||
(
i_am_writer &&
(forkable() && (
(parent && show_cache && exit(STALE))
||
(child && update_cache && exit(0)
))
|| (update_cache && exit(CURRENT)
)
Prince "--'s here I come! Where is the preview button for comments? Why is this TEXTAREA so small? I cant see anything?" PAWN
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.