My friend wanted to remove this banner ... so I wrote a nice perl script for him. The script traverses the whole directory tree of the downloaded site and removes the html lines that create the banner from each page.<!-- inserted banner --> <TABLE> blah blah </TABLE> <!-- end of inserted banner -->
It works pretty well, and I'm quite happy with that ... and my friend is happy too :). Anyway in the process of continuous learning I started thinking of rewriting again the script to take advantage of -p command switch, and here is what I ended up with:use strict; use File::Find; die "usage $0 <dir>" unless (@ARGV == 1 && -d $ARGV[0]); find ( sub { return unless -f $_; open (FILE, "< $_") or warn "cannot read $_\n" and return; my @lines = grep {!(/inserted banner/i .. /end of inserted ban +ner/i)} <FILE>; close (FILE); open (FILE, "> $_") or warn "cannot write $_\n" and return; print FILE @lines; close (FILE); }, $ARGV[0] );
Moral: there is more than one way to do it :)perl -MFile::Find -pi.bak -e "BEGIN {find sub {-f && push @ARGV, $File +::Find::name}, \".\"} if (/inserted banner/i) {while (<>) {s/.*// and last if /end of insert +ed banner/i;}}"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Marcos' Meditation
by mdillon (Priest) on May 26, 2000 at 20:27 UTC | |
by marcos (Scribe) on May 29, 2000 at 20:33 UTC |