This is to test<X-REF REFID="FN001">1</X-REF> some more text. <FTN ID="FN001">Example111</FTN>
This is to test<X-REF REFID="FN002">2</X-REF> some more text. <FTN ID="FN002">Example222</FTN>
This is to test<X-REF REFID="FN003">3</X-REF> some more text. <FTN ID="FN003">Example333</FTN>
EXPECTED OUTPUTThis is to test<X-REF REFID="FN001">1<FTN>Example111</FTN></X-REF> some more text.
This is to test<X-REF REFID="FN002">2<FTN>Example222</FTN></X-REF> some more text.
This is to test<X-REF REFID="FN003">3<FTN>Example333</FTN></X-REF> some more text.
This is the full perl script now i am usingopen(IN, "<temp.in") || die "\n Can't open file\n $!\n";
open(OUT,">temp.out");
## Search for FTN
my %values;
while(<IN>) {
if(s/\<FTN ID\=\"FN(\d{3})\"\>(.+?)\<\/FTN\>/\<FTN$1\>/) {
$values{$1} = $2;
}
}
## replace X-REF
while(<IN>) {
s/(<X-REF REFID="FN(\d{3})">)(.+?)(<\/XREF>)/$1$values{$2}$3/;
print OUT;
}
close(IN);
close(OUT);
But i don't get any output in temp.out
In my input file X-REF occurs first and FTN occurs next. So my script is not working properly
In reply to with better example
by texuser74
in thread replacing text in specific tags
by texuser74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |