Internet Technology
Certificate
HTML2PERL
A Perl UNIX command line program to translate an HTML file into Perl print
statements for use in Perl programming. Copyright 1999 by Ray Trygstad
<trygstad@trygstad.org>;
used by permission.
#!/usr/local/bin/perl
&ReadFile;
&PrintFile;
sub ReadFile
{
print "\n";
print "This program will convert an HTML file to perl print statements.\n";
print "The filename must have a .htm or .html extension and must not contain\n";
print "the phrase \"html\" or \"htm\" elsewhere in the file name. The output file\n";
print "will have the same name as the input file with an extension of \".print\".\n";
print "NOTE: If the output file already exists it will be overwritten.\n\n";
print "What is the name of the file you wish to convert? ";
$FileName = <STDIN>;
chomp $FileName;
print "\nThe file you requested was $FileName\n";
open (INFILE, $FileName);
@ReadFile=<INFILE>;
close (INFILE);
chomp @ReadFile;
}
sub PrintFile
{
$FileName=~s/ht.*/print/i;
$outfile=$FileName;
`touch $outfile`; #Creates the outfile
`chmod 666 $outfile`; #Sets permissions for the outfile
open (OUTFILE, ">$outfile");
foreach $line (@ReadFile)
{
$line=~s/'/\\'/g;
$line=~s/"/\\"/g;
$line=~s/\Q$/\Q\$/g;
$line=~s/@/\\@/g;
# $line=~s/\Q\/\Q\\/g; #Can't get this one to work!
print OUTFILE " print \"$line\\n\";\n";
}
close (OUTFILE);
print "\nFile \"$outfile\" was created.\n\n";
}
############################################################
# html2perl.pl runs from the UNIX command line to convert #
# HTML files to perl print statements. #
# Copyright 1999 Ray Trygstad <trygstad@trygstad.org>; #
# may be reused for non-commercial purposes if accompanied #
# by this copyright statement. #
# No warranty of suitability for any purpose is implied #
# or included; all use is at your own risk. #
############################################################
IIT Webmaster
- Last Updated November 2, 1999 by
Ray Trygstad trygstad@iit.edu