#!/usr/local/bin/perl # # Get rid of given block element (typically div) of the given class # Arnaud Le Hors - lehors@w3.org # $Id: htmltrim,v 1.1 1997-09-19 13:55:46 lehors Exp $ $PROGNAME = substr($0, rindex($0, "/") + 1); if ($#ARGV < 2) { print "Usage: $PROGNAME element class input output\n"; exit 1; } $elem = $ARGV[0]; $class = $ARGV[1]; $input = $ARGV[2]; if ($ARGV[3]) { $output = $ARGV[3]; } else { $output = "-"; } # copy file in memory sub readfile { $buf = ""; if (!open(INPUT, $_[0])) { print STDERR "$PROGNAME Error: Cannot open file: $_[0]\n"; return; } while () { $buf .= $_; } close(INPUT); } readfile($input); $buf =~ s/<$elem[ \t\n]+[^>]*class=["']?$class(>|["' \t\n]+[^>]*>).*?<\/$elem>//sigoe; open(OUTPUT, "> $output"); print OUTPUT $buf; close(OUTPUT);