mkphlog v0.3 and bug wrangling
Wednesday, Jan 18 04:34:03 pm, 2012
This weekend, chals emailed me with a bug in the new mkphlog. For some
odd reason, it would only automatically add 7 posts to the main phlog
listing before failing miserably to write the new posts to the listing.
Now, the the easy thing would be to disable that function with the handy
boolean variable provided in the new version of mkphlog. But I wanted to
fix the script, so I had to do some light debugging. However, what I
found was interesting.
[Skip the next 3 paragraphs if you don't want to hear the gory,
slightly dramatized details]
The mistake I made is that I made an assumption in writing the original
script. For those not really into programming, _never_ make
assumptions. Sometimes you're right, but when you're wrong, you're left
scratching your head in confusion. The assumption I made was that the
output of `wc -l` is always the same. It isn't, especially on NetBSD
(SDF's operating system), but what's worse is that it isn't standardized
across platform. (The wc on Slackware doesn't output the same thing as
the wc on NetBSD).
The problem with this is that the program would work fine on NetBSD
until a certain line number was reached (10, or anything above one
digit). Then cut, when trying to split the output into a set number
of fields with a space character as a deliminator, would be one
field off and extract sweet nothing from the `wc -l` output.
It didn't even work at all on Slackware where there is no odd
formatting at the beginning. Which led me to fix the whole issue
with a few simple sed substitutions; just get rid of everything
that I don't want until there is nothing left but the line count.
Let this be a lesson. Be careful how you program :) and don't make any
assumptions. That would be a good start. And above all else, have fun
coding.
(DIR) Download mkphlog v0.3 here