Wednesday, March 2, 2011

Converting code for Blogger

Here's a simple PERL script that converts a code file for pasting into Blogger. And yes, I used it to convert itself for this post. HOW COOL IS THAT??? LOL. If anyone knows of a free, online one that's better, lemme know.

pastable.pl



if (@ARGV < 1){
        die "Usage filename\n";
}
$filename = shift(@ARGV);

@fn = split(/\./,$filename);
$outname = $fn[0]."-pastable\.html";

open (INPUT,"<$filename");
open (OUTPUT,">$outname");

print OUTPUT "<font size=-1>";
while (<INPUT>){
        $line = $_;

        $line =~ s/\&/&amp;/g;        
        $line =~ s/</&lt;/g;        
        $line =~ s/>/&gt;/g;
        $line =~ s/\"/&quot;/g;
        $line =~ s/\n/<BR>/g;
        $line =~ s/\t/        /g;
        $line =~ s/ /&nbsp;/g;

        print OUTPUT $line;
}
print OUTPUT "</font>";

No comments:

Post a Comment