Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Zap the Gremlins

Invisible characters, sometimes referred to as gremlins, interspersed in text files, can nevertheless become visible as strange characters when displayed in a browser. Further, if the file is used as a template where certain sequences of characters need to be replaced, gremlins within the sequence can abort the replacement.

Here is a Perl CGI script that may be used to strip out unwanted invisible whitespace characters.

#!/usr/bin/perl
use strict;
my $inFileName = 'file.txt';
my $outFileName = 'newfile.txt';
local $/;
open R,"<$inFileName";
binmode R;
open W,">$outFileName";
for(split //,<R>)
{
	print W if /[\n\r\t]/ or (ord($_) >= 32 and ord($_) < 127);
}
print "Content-type: text/html\n\ndone";

In the script, specify the file to read in and the file to write out. Make these different file names. The "out" file will overwrite anything with the same name, so choose the file name carefully.

Return and linefeed characters will be retained, as will tab and regular space characters. All other whitespace characters are removed.

Note:
If you don't already know how to install a CGI script, here are the basic CGI script installation instructions that apply to all of them.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC