[please limit your line lengths to 72 characters]
[please make sure your blank lines are *actually* blank]
Gregory Toomey <> wrote:
> 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
There is absolutely no need to use bash. If nothing better, use the
techniques described in perldoc perlipc "Safe Pipe Opens". Better, use
a tied filehandle or a PerlIO layer on STDOUT. Or simply generate the
thing without superflous whitespace in the first place.
<snip>
> 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;
You realise this changes the presentation of the HTML?
> #newlines are not needed
> #except for Content-type-text/html\n\n
> # which occurs at the start
> print;
> print "\n" if $count++<4;
Why 4?
> }
'A little buggy'? The whole idea's fundamentally flawed: you need to
start by separating the HTTP from the HTML from the data, which means
using an HTML parsing module. For instance, what about this:
<link
rel=stylesheet
type="text/css"
href="..."/>
Or this:
Status: 302 Found
Location: ...
Content-encoding: ...
Content-type: text/html
Content-length: ...
<html>...
Or this:
<pre>
#!/usr/bin/perl
use warnings;
use strict;
print "Hello world\n";
</pre>
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|