Twice in the last week, I've wanted to create a table of contents for an HTML document. In both cases they've been documents that I've written, so the structure has been pretty well defined and I started to wonder whether I could automate the process.
I decided that HTML::TreeBuilder would be the right tool and started to take a closer look at the module. It's the first time I've every really used it for anything useful.
The result (after about an hour of hacking) is toc.pl. Currently it's pretty closely tied to the structure of my documents (it relies on the existance of
<div> sections called "front" and "body") but it can very easily be used as a basis for other similar scripts.
Share and enjoy