http://www.perlmonks.org?node_id=76679
Category: HTML Utility
Author/Contact Info patgas
Description: This script grabs an HTML file, and converts it into a VBScript Response.Write command for use in ASP pages. Allows custom levels of indenting, and does proper double-quote escaping. Simple, really, but I find myself using it all the time.
# HTML2ASP
# By patgas
# April 30, 2001
#
# Takes an HTML file, and converts it into a
# Response.Write command for an ASP page.
#
# Usage:
#    perl html2asp.pl [input_file] [output_file] (command_indent) (HTM
+L_indent)
#    
#    input_file and output_file are required.
#    command_indent inserts whitespace before the actual Response.Writ
+e command.
#    HTML_indent inserts whitespace in the string argument to Response
+.Write.

my ($infile, $outfile, $indentCommand, $indentHTML) = @ARGV;

die "Missing required argument: $!" if (!$infile || !$outfile);

$indentCommand ||= "2";
$indentHTML ||= "0";

open(IN, $infile) or die "Can't open input file: $!";
open(OUT, ">$outfile") or die "Can't open output file: $!";

print "Starting... ";

select(OUT);

print "<%\n\n";

$indentCommand = ' ' x $indentCommand;
$indentHTML = ' ' x $indentHTML;

my @lines = <IN>;
my $writeCommand = 1;

while (@lines) {
    chomp(my $line = shift @lines);

    print $indentCommand;

    if ($writeCommand == 1) {
        print "Response.Write(";
        $writeCommand = 0;
    }
    else {
        print "               ";
    }

    print $indentHTML;

    if ( $line ) {
        $line =~ s/\"/\"\"/g;
        print "\"$line\" & ";
    }

    print "vbNewLine";

    if (@lines) {
        print " & _";
    }
    else {
        print ")\n";
    }

    print "\n";
}

print "%>";
print STDOUT "Done.";

close IN or die "Can't close input file: $!";
close OUT or die "Can't close output file: $!";