in reply to Re: replacing text in specific tags
in thread replacing text in specific tags
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: with better example
by CombatSquirrel (Hermit) on Aug 21, 2003 at 12:09 UTC | |
by texuser74 (Monk) on Aug 22, 2003 at 01:15 UTC | |
by CombatSquirrel (Hermit) on Aug 22, 2003 at 11:03 UTC | |
by texuser74 (Monk) on Aug 25, 2003 at 04:33 UTC | |
by CombatSquirrel (Hermit) on Aug 25, 2003 at 08:51 UTC | |
| |
|
Re: with better example
by Abigail-II (Bishop) on Aug 21, 2003 at 11:12 UTC |