in reply to Replacing a text in XML.
my $twig = XML::Twig->new( twig_handlers => { subfield => \&editHref, }, pretty_print => 'indented', ); $twig->parse($xml); $twig->print; sub editHref { my ( $twig, $href ) = @_; my $text = $href->text(); my $orig = "(OSt)16"; $text =~ s/\Q$orig/(OSt)20/; $href->set_text($text); }
Or, just avoid the regex...
sub editHref { my ( $twig, $href ) = @_; my $text = $href->text(); $href->set_text('(OSt)20') if $text eq '(OSt)16'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replacing a text in XML.
by bendon (Novice) on May 21, 2013 at 15:36 UTC |