in reply to Read/Change files in a Directory
Lacking a few details, but here is how I would approach this:
use strict; use XML::Simple; my $xs = XML::Simple->new(KeepRoot=>1); my $data; { local $/; $data = <DATA>; } my $inStruct = $xs->XMLin($data); my $outStruct; foreach my $tag (@{$inStruct->{Root}->{'dc:subject'}}) { my @matches = $tag->{content} =~ /(\d+th century)/g; foreach my $match (@matches) { my %item = %$tag; $item{content} = $match; push(@{$outStruct->{Root}->{'dc:subject'}}, \%item); } } my $resultXML = $xs->XMLout($outStruct); print $resultXML; __DATA__ <Root> <dc:subject xml:lang="en-US">18th century 17th century</dc:subject> <dc:subject xml:lang="en-US">18th century 14th century</dc:subject> <dc:subject xml:lang="en-US">18th century 12th century</dc:subject> <dc:subject xml:lang="en-US">18th century 11th century</dc:subject> <dc:subject xml:lang="en-US">18th century 10th century</dc:subject> <dc:subject xml:lang="en-US">18th century 12th century</dc:subject> <dc:subject xml:lang="en-US">18th century 12th century 12th century 12 +th century 12th century</dc:subject> </Root>
|
|---|