December 2017 Update: More changes, described at end of article.
October 2017 Update: I regret that I let this article get badly out of whack
with reality. Notably, most of the links to my code, which were on the
old UNH "pubpages" server, went stale when I retired. In addition, I've cleaned up the code
some and fixed a nasty Daylight Savings Time-related bug. I hope.
Further notes at the bottom of the article.
Note: this post is out of whack with normal Pun Salad
content. Only recommended for:
- computer geeks who (like me)
tend to approach everyday issues by asking: how could I write
code to make this easier?; or
who might be interested in whatever mental aberration causes
the behavior exhibited in (a).
A few years back I noticed I was doing a miserable job
of reading the magazines to which I was subscribed; the new
issue would show up and I would have just read few if any
articles in the previous one.
A similar problem with books: I would check them out of the
library and return them unread. And my to-be-read pile of
owned books just was getting bigger.
What worked for me was to set up a reading schedule for each "new"
book or magazine. Simply read through a reasonable, fixed number of pages
each day, until done. Lather, rinse, repeat.
I'm currently implementing this scheme by generating a calendar-format
for each item in HTML. Example for a book I read back in 2014,
Freedom™ by Daniel Suarez:
I (1) print the schedule from my web browser,
(2) cut it out, (3) attach to a card, and (4) use the
result as a bookmark
for the item. And each day, I try to meet the page goal for
(Not that it matters, but for magazines I staple the schedule
to one of the subscription cards that invariably accompany
each issue. For books, I tape it to one of the plastic
advertising cards the Yankee Candle company sends us, which are
significantly more substantial.)
Now I'm not psycho about this: it's OK to get ahead of the goals
if the material is compelling and I have the time. It's also
OK to fall behind if there's just too much other stuff going
on. (However, in my experience, just knowing that I've "fallen
behind" is just enough self-nudging motivation to carve out some
extra time to catch up later.)
Enough for the mechanics, on to the code. For a long time I ran a Perl
script from a Linux command line to generate
a schedule. But I realized that it would be
(slightly) more flexible to set up an HTML
form to get the schedule parameters, calling a CGI backend
to display the result.
The form I'm using is here. (Do I
have to mention that you can use your browser's source-viewing
capabilities to view the HTML source? Nah, probably not.)
[December 2017: there used to be a screen shot here. That's silly. Just visit
the form to see what it looks like.]
[December 2017: removed paragraph about the jQuery datepicker, no longer
The form also uses a CSS stylesheet
here; I originally wrote
it to make the documentation I wrote at UNH look better, and it has a
lot of cruft. Feel free to steal and clean it up.
So you fill out the form, for example:
[Note: it doesn't look exactly like this any more. I urge you to
… hit the submit button and the resulting page should produce
the appropriate schedule. (I'm pretty sure it would work for
you if you want to try it.)
The real work is performed by the
Perl CGI script, which relies heavily on the smarts contained in the
modules. If you'd like to look at that (feel free to adapt it to
your own preferences if you are so inclined):
the plaintext Perl file is
and the html-prettyprinted version is
The HTML template used by the script is also important
and that's here.
Additional notes (October 2017).
December 2017 Update
As previously mentioned, the original version of the CGI script lived on
the UNH "pubpages" webserver, where I enjoyed
It's now on the Pun Salad server, where I don't. This is problematic
when you need to install some random CPAN perl module.
Solution (or, at least, what I'm doing): use
to install necessary modules "unprivileged" and
in scripts to find them. (This seems to work for CGIs, surprisingly.)
The most recent bug squashed was one I've struggled with for years: if
your timezone does DST, not all days are 24 hours: the "spring forward"
day has only 23; the "fall back" day has 25. This resulted in strange
behavior when a reading schedule traversed one of those days.
The fix turned out to be relatively easy: tell the script to pretend
it's in the UTC timezone. Duh. That's accomplished by (for example)
$startdate->config( 'setdate', 'now,UTC' );
: Some minor surgery on this tool to report.
After years, I noticed that, in many cases, I wanted to spend a specific
number of days reading a book or magazine. This involved me looking at a
calendar, and finger-counting to figure out what end-date to specify in the form.
Duh. That's an unforgivable user interface sin, is it not?
So the input form now requests either (a) the end-date for the reading
schedule, or (b) the number of days the schedule should run from the
If you enter both, the end date will be ignored, but why would you do
I would put up a screen shot, but you can just
at the actual form.
The form has been otherwise (ahem) brought into the 21st century. Title,
start date, start page, and end page input fields now sport the HTML
type attribute is used
specify that the title should be
text, the start/end
pages should be
number, and the start/end dates should be
That means the web browser's native date-picker UI will be used for
date entry instead of the previous jQuery datepicker. (Some old browsers
don't support this, but since I'm not being paid to support old
browsers, I can say "gee, that's too bad", without guilt.)
page has to be less than the end page, either the number-of-days or the
end-date input has to be there, and if the end-date is specified, it has
to be after the start date.
Web Security 101 saith: your CGI must still check the validity of its
inputs. So all that code is still in the CGI. But…
I also modified the CGI script to use the Perl
module for calendar arithmetic instead of
greatly simplified the code, and (somewhat surprisingly)
seems to do the right thing when the reading schedule overlaps a
Daylight Saving time warp.
I still think
Date::Manip is vital for heavy-lifting
Date/Time calculations. But it's overkill here.