Back in June, Blogger busted itself slightly by starting to insert divs at the top and bottom of each entry body to clear floats. I'm guessing they did it to be sure that entries with floated images in them don't end up stacked next to each other. The problem is that I (and some others, I'd guess) have modified my blog template, adding a float that sits next to the blog entries. This div holds AdSense ads. If my entry is long enough, it doesn't matter, but most of my entries are shorter than the AdSense ads, which results in the author and other information that comes after the entry body, as well as all following entries, being pushed down the page far enough that they're probably out of site unless one decides to scroll down the page, without having any clue that there might be something worthwhile down there.

I reported the problem to Blogger a while back, and they said a fix is in the works. But now I've gotten tired of waiting, so I've created my own fix. Here's the Perl script that I run after posting to delete the extraneous divs. Note that my blog filenames end in ".php". If yours end in ".html" or anything else other than ".php", you'll need to change the script as appropriate. This script only processes one directory at a time, so there's certainly room for improvement.

#!/usr/bin/perl

if ($#ARGV==0) {
 chdir $ARGV[0];
 if (opendir(dirHandle,'.')) {
  @files=readdir(dirHandle);
  closedir(dirHandle);
  foreach $fileName (@files) {
   if ($fileName=~/\.php$/o) {
    if (open(fH,$fileName)) {
     @f=;
     close fH;
     for ($i=$#f,$c=0;$i>=0;$i--) {
      $c1=($f[$i]=~s/<div style="clear:both;"><\/div>//go);
      $c2=($f[$i]=~s/<div style="clear:both; padding-bottom: 0.25em;"><\/div>//go);
      if ($c1||$c2) { $c=1; }
     }
     if ($c) {
      if (open(fH,">$fileName")) {
       print fH @f;
       close fH;
      } else { print "ERROR: Couldn't open $fileName for writing\n"; }
     }
    } else { print "ERROR: Couldn't open $fileName for reading\n"; }
   }
  }
 } else { print "ERROR: Couldn't open directory $ARGV[0]\n"; }
} else { print "Usage: zapgoogledivs.pl <DIRECTORY>\n"; }