G
Gregory Toomey
A few weeks ago a question was asked in this group about removing whitespace from html, in particular from html generated by cgi.
Here's a simple technique I developed for Linux:
1. A sample cgi. Bash uses the <<'delimiter' conststuct to pass the input verbatim to Perl. The output of the cgi is piped to delspace.pl. our whitespace munger.
#!/bin/bash
/usr/bin/perl <<'EOFPERL' | ./delspace.pl
#your cgi goes here
use strict;
$|++;
print "Content-type:text/html\n\n";
print " <h1> This is a test <h1> \n";
print " some more text\n";
EOFPERL
2. Now here's delspace.pl, the whitespace remover. It may be a little buggy, but it seems to work for my simple html.
#!/usr/bin/perl
my $count=0;
while(<>){
# remove trailing whitespace
s/^\s+//;
# remove leading whitespace
s/\s+$//;
# change internal whitespace to single space
s/\s+/ /g;
# remove simple one line comments
s/<!--.*?-->//;
# another simple whitespace removal
s/> </></g;
#newlines are not needed
#except for Content-type-text/html\n\n
# which occurs at the start
print;
print "\n" if $count++<4;
}
gtoomey
Here's a simple technique I developed for Linux:
1. A sample cgi. Bash uses the <<'delimiter' conststuct to pass the input verbatim to Perl. The output of the cgi is piped to delspace.pl. our whitespace munger.
#!/bin/bash
/usr/bin/perl <<'EOFPERL' | ./delspace.pl
#your cgi goes here
use strict;
$|++;
print "Content-type:text/html\n\n";
print " <h1> This is a test <h1> \n";
print " some more text\n";
EOFPERL
2. Now here's delspace.pl, the whitespace remover. It may be a little buggy, but it seems to work for my simple html.
#!/usr/bin/perl
my $count=0;
while(<>){
# remove trailing whitespace
s/^\s+//;
# remove leading whitespace
s/\s+$//;
# change internal whitespace to single space
s/\s+/ /g;
# remove simple one line comments
s/<!--.*?-->//;
# another simple whitespace removal
s/> </></g;
#newlines are not needed
#except for Content-type-text/html\n\n
# which occurs at the start
print;
print "\n" if $count++<4;
}
gtoomey