[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] find and finddepth




I've written a small script that traverses a directory tree and does some
inplace editing on HTML files. Curiously, when I use find to do a
breadth-first traversal the script seems to get stuck when it encounters a
directory. With finddepth it's as fast as one would expect.

BTW, I tried to have perl do the inplace editing, but I couldn't get the
$^I stuff to work and I don't know how to set the -i command line switch
for a droplet.


Here's the interesting part of the script, maybe there's something I've
done wrong?

sub wanted {
	if (-f $File::Find::name) {
		process($File::Find::name);
	}
}

sub process {
	my $path = shift(@_);
	return unless $path =~ /\.(html|htm)$/i;
	print STDERR "Processing $path\n";

	$tmpfile = $path . '~';

	rename($path, $tmpfile);
	open(INFILE, $tmpfile) || die "Couldn't open file $tmpfile: $!\n";
	open(TMPFILE, ">$path") || die "Couldn't open file $path: $!\n";

	while (<INFILE>) {
		s/<!--[^>]*-->//ig;
		s/<META[^>]*>//ig;
		s/<x-sas-window[^>]*>//ig;

		print TMPFILE;
	}

	close(INFILE);
	close(TMPFILE);

	unlink($tmpfile);
}


Michael

---
Michael Schuerig                 Papa, draussen steht ein Philosoph.
mailto:uzs90z@uni-bonn.de        Sag ihm, wir kaufen nichts.
http://www.uni-bonn.de/~uzs90z/