trunk
Line | |
---|
1 | #! /usr/bin/perl -w |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my $source = shift @ARGV || die "usage: $0 source.html filtered.html"; |
---|
7 | my $dest = shift @ARGV || die "usage: $0 source.html filtered.html"; |
---|
8 | if (! -r $source) { |
---|
9 | die "$0: cannot read $source"; |
---|
10 | } |
---|
11 | if (-e $dest) { |
---|
12 | die "$0: file exists! $dest"; |
---|
13 | } |
---|
14 | |
---|
15 | open SOURCE, "<$source"; |
---|
16 | open DEST, ">$dest"; |
---|
17 | |
---|
18 | binmode(DEST); |
---|
19 | |
---|
20 | my $inscript = 0; |
---|
21 | my $startre = '<script\b[^>]*>'; |
---|
22 | my $endre = '</script>'; |
---|
23 | |
---|
24 | while (my $line = <SOURCE>) { |
---|
25 | while ($line =~ /$startre/) { |
---|
26 | $line =~ /^(.*?)$startre(.*)(\r?\n)$/; |
---|
27 | if ($inscript == 0) { |
---|
28 | print DEST "$1"; |
---|
29 | } |
---|
30 | $inscript++; |
---|
31 | $line = "$2$3"; |
---|
32 | } |
---|
33 | |
---|
34 | while ($line =~ /$endre/) { |
---|
35 | $line =~ /^(.*?)$endre(.*)(\r?\n)$/; |
---|
36 | if ($inscript <= 0) { |
---|
37 | warn "$0: something wrong"; |
---|
38 | } |
---|
39 | $inscript--; |
---|
40 | $line = "$2$3"; |
---|
41 | } |
---|
42 | |
---|
43 | if ($line && $inscript <= 0) { |
---|
44 | print DEST $line; |
---|
45 | } |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.