Thread RE recursion
(24 answers)
Opened by linuxCowboy at 2014-04-15 20:19 Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #!/usr/bin/perl package FilterDiv; require HTML::Filter; @ISA = qw(HTML::Filter); sub start { my $self = shift; $self->{div_seen}++ if $_[0] eq "div"; $self->SUPER::start(@_); } sub end { my $self = shift; $self->SUPER::end(@_); $self->{div_seen}-- if $_[0] eq "div"; } sub output { my $self = shift; unless ( $self->{div_seen} ) { $self->SUPER::output(@_); } } 1; my $p = FilterDiv->new or die; $p->parse_file(*DATA) or die; __DATA__ <!-- aaaa --><b>a</b> <div > 123<div >aaaa</div> Text <div .. >a</div > .. </div > Text ergibt: <!-- aaaa --><b>a</b> Text Last edited: 2014-04-17 12:13:01 +0200 (CEST) |