wolverina has asked for the wisdom of the Perl Monks concerning the following question:

When i run this code, it displays in the browser window formatted.
Textfile = "file.htm"; open (FILE,"$FORM{'TextFile'}"); @LINES = <FILE>; close (FILE); $text = join(' ',@LINES); $text =~ s/\n/ /g; foreach $variable (@variables) { if ($FORM{$variable} eq "") { print "incomplete!\n"; exit; } $text =~ s/<!--$variable-->/<STRONG>$FORM{$variable}<\/STRONG> +/g; } $text =~ s/A\/an <STRONG>(a|e|i|o|u)/An <STRONG>$1/g; $text =~ s/a\/an <STRONG>(a|e|i|o|u)/an <STRONG>$1/g; $text =~ s/A\/an/A/g; $text =~ s/a\/an/a/g; print $text;
But when i add this to the bottom, to write the contents to a file, the resulting file is not formmated.
open(OUT,">$Textfile") or die $!; print OUT "$text\n" or die $!; close(OUT) or die $!;
Would anyone know why the browser displays the contents formatted, but the file is saved unformatted? Thanx, Lisa.

Replies are listed 'Best First'.
Re: Retain file format
by Zaxo (Archbishop) on Aug 14, 2002 at 05:51 UTC

    The browser doesn't care whether there are newlines in the html or not. It takes its formatting from the html markup. To preserve the format of the rewritten file, don't do $text =~ s/\n/ /g;.

    After Compline,
    Zaxo