Cleanparser was originally written out of a need. I had been creating small websites for several families and while these sites were simple, they often had repetitive content but weren’t dynamic. I therefore found that much of my time was spent going through pages and ensuring that these blocks of repetitive content were all consistent. This was a time consuming, tedious and error prone process. I knew there had to be a better way.
I happened to be at a Micro Center one day and noticed a bargain book about Perl and realized that this problem would provide a perfect opportunity to learn Perl. After I got home, I sat down with the book and started to hack away. Eventually I got a script that worked, it wasn’t the quickest script nor was it the prettiest but it definitely worked. I have used it for many years since I wrote it. I now look back and realize that the code is actually quite grotesque and is totally inefficient. However everytime I think about changing it, the old saying “if it ain’t broke, don’t fix it” has gotten the better of me.
I offer it up here as I have found it immensely useful and it demonstrates my desire to pickup new things in order to fulfill a need. Despite the code being a glorious mess, I still feel that this project was an overall success due to the vast amounts of time it has saved me. If you would like a copy, just download it from the link at the bottom.
Instructions
- Create a project directory for your new website.
- Create a directory named “snp” within this new directory.
- Create a file named “header.snp” and fill that file with some text you would like to repeat throughout the site. (The filename can have any alphanumeric string before the extension but the string can’t contain spaces)
- Create an HTML file with an extension of “.html” inside of your project directory. (Ex. index.html)
- Inside that file create a block like this:
<!--SNP:header--> <!--/SNP:header-->
- Save the file and close it.
- Open a terminal and change to the directory of your new project.
- Run “perl cleanparser.pl ./”
- Now open the HTML file you created and see how the program has inserted the contents of header.snp in between the tags in your HTML file. Remember anything you place between those tags will be replaced when you run cleanparser. Enjoy.
