ilottl has asked for the wisdom of the Perl Monks concerning the following question:
Where am I going wrong! Please help.use strict; use File::Find; use HTML::TokeParser; my $bak_ext = '.bak'; my $root_dir = 'C:/Temp/Chris'; find(\&wanted, $root_dir); sub wanted { # if the extension fits... if ( /\.xml?/i ) { print "Processing $_\n"; my $new = $_; my $bak = $_ . $bak_ext; rename $_, $bak or die "Cannot rename $_ to $bak: $!"; open NEW, "> $new" or die "Cannot open $new for writing: $!"; my $p = HTML::TokeParser->new( $bak ); while ( my $token = $p->get_token ) { my $text_index = $token->[0] eq 'T' ? 1 : -1; $token->[ $text_index ] =~ s/<label>CA 3<\/<label>\/Scrap/i; print NEW $token; } close NEW; } else { print "Skipping $_\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Performing a search and replace in XML across multiple directories
by samtregar (Abbot) on May 16, 2006 at 22:08 UTC | |
by ilottl (Novice) on May 16, 2006 at 22:11 UTC | |
by ilottl (Novice) on May 16, 2006 at 22:57 UTC | |
by GrandFather (Saint) on May 16, 2006 at 23:43 UTC | |
by ilottl (Novice) on May 16, 2006 at 23:37 UTC | |
by ilottl (Novice) on May 18, 2006 at 22:30 UTC |