in reply to Formatting a text file for browser

Here is the bare bones of what you need to do. You need to escape HTML special. If you want to use something other than <pre> tags you also need to change multiple spaces and tabs into &nbsp; and replace \n with <br>

In this example we wrap the result in <pre> tags to get a fixed width font accurate display of the original text. Tabs are rendered as 4 spaces.

Update

The escapeHTML method this example did use is documented as an internal CGI.pm method so I have re-coded it here as it is naughty to use internal methods. I have also added the PerlMonks square bracket escape. It does not hurt anything.

#!/usr/bin/perl -w my $text = "c:/text.pl"; open TEXT, $text or die "Oops can't open $text $!"; open HTML, ">$text.htm" or die "Oops can't write $text.htm $!"; print HTML "<pre>\n"; while (<TEXT>) { $_ = escapeHTML($_); print HTML $_; } print HTML "</pre>\n"; close HTML; close TEXT; sub escapeHTML { local $_ = shift; # make the required escapes s/&/&amp/g; s/"/&quot;/g; s/</&lt;/g; s/>/&gt;/g; # make the whitespace escapes - not required within pre tags s/\t/&nbsp;&nbsp;&nbsp;&nbsp;/g; s/( {2,})/"&nbsp;" x length $1/eg; # make the brower bugfix escapes; s/\x8b/&#139;/g; s/\x9b/&#155;/g; # make the PERL MONKS escapes (if desired) s/\[/&#091;/g; s/\]/&#093;/g; # change newlines to <br> if desired # s/\n/<br>/g; return $_; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print