[HRPM] works but ugly
Troy E. Webster
twebster at pcs.cnu.edu
Thu May 11 11:17:54 CDT 2000
Ok,
I wrote this little script to take care of large blocks of white space and
also to strip off windoze generated carriage-returns/newlines from html
pages. Trust me, it is usefull to me in certain situations.
Problem is I don't know how a '^M' (or windoze carriage return) is
represented in perl, so I just yank off two characters using chop() and
hope for the best. Definetly not bullet proof. If anyone knows how I
could better this please let me know. It's my first perl program from
scratch.
thanks
Troy
****************************************************************
#!/usr/local/bin/perl -w
######################################################
# code.pl
#
# This is a simple script which will process html files
# and remove annoying blank lines in an html page's
# source code which are generated by software packages
# such as Cold Fusion. Hand-editing these pages is
# tedious.
#
# ERROR: If a line contains only a single letter and
# a \n (or a line with only two characters)
# then this script will chop it out. The
# assumption is that no html file will exhibit
# this characteristic.(bad assumption)
#
# NOTE: This script will work on pages generated by
# a UNIX platform-specific application OR a
# page which was created in Windows. (there
# are different "newlines" associated with each)
#
# AUTHOR: Troy Webster May 2000
######################################################
die "Usage: code.pl [filename]\n" if (@ARGV < 1);
foreach (@ARGV) {
print "Processing file: $_\n";
my @lines;
if(open(FH, "<$_"))
{
@lines = <FH>; #throw it into an array
close(FH);
if(open(FH,">$_"))
{
foreach(@lines)
{
if ($_ eq "\n")
{
print "removing blank line.\n";
chop $_;
}
elsif (length($_) == 2) # not the answer,
# but it works
{
print "Length is 2\n";
chop;
chop;
}
print FH $_;
}
close(FH);
}
else
{
die "File $_ not written.\n";
}
}
else
{
die "File $_ not opened.\n";
}
}
exit;
___________________________________________________________________________
- improvise, adapt, overcome -
www.pcs.cnu.edu/~twebster/
---------------------------------------------------------------------------
More information about the Norfolk-pm
mailing list