[vox-tech] Perl script help

Richard Crawford vox-tech@lists.lugod.org
Wed, 24 Mar 2004 15:32:58 -0800 (PST)


This script is supposed to remove everything between <form and reset>. 
Yet, when I run it, it gives me this error:

print() on closed filehandle THENEWFILE at boardclean.pl line 23.
Cannot print!! Bad file number

I cannot see my programming error.  Can anyone help?

======================================================
#!/usr/local/bin/perl

use strict;

my $curdir = shift;
my $file = "";
my $tmprs = "";
my $data = "";

opendir(DIR, $curdir) or die "Cannot open directory $curdir: $!";
while (defined ($file = readdir(DIR))) {
	open(THEFILE, "$file");
	$tmprs = $/;
	undef $/;
	$data=<THEFILE>;
	close(THEFILE);
	$/ = $tmprs;
	$data =~ s|<form.*reset>|<!-- form action removed -->|gm;
	open(THENEWFILE, ">$file");
	print THENEWFILE $data or die "Cannot print!! $!\n";
	close (THENEWFILE);
}

======================================================

-- 
Sláinte,
Richard S. Crawford (AIM: Buffalo2K)
http://www.mossroot.com   http://www.stonegoose.com/catseyeview
"It is only with our heart that we can see clearly.  What is essential is
invisible to the eye."  --Antoine de Saint Exupery