in reply to Re: with better example
in thread replacing text in specific tags
Once again thanks for your support.open(IN, "<temp.in") || die "\n Can't open file\n $!\n"; open(OUT,">temp.out"); ## Search for FTN my %values; # read through the input fileto get the values while(<IN>) { if(/<FTN ID="FN(\d{3})">(.+?)<\/FTN>/) { #no need to quote <, >, + ", = $values{$1} = $2; } } close(IN); open(IN, "<temp.in") || die "\n Can't open file\n $!\n"; ## replace X-REF while(<IN> ) { s/<FTN.+?<\/FTN>//; # get rid of existing <FTN> tags - we alrea +dy have the values from them s/(<X-REF REFID="FN(\d{3})">.*)(<\/X-REF>)/$1<FTN>$values{$2}<\ +/FTN>$3/; # alter the X-REF LINE print OUT; } close(IN); close(OUT);
edited by ybiC: Replace opening <pre> tag with <code> as per Monastery convention *and* add closing tag for same
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Efficiency issues in text parsing
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 | |
by texuser74 (Monk) on Aug 27, 2003 at 00:44 UTC | |
by CombatSquirrel (Hermit) on Aug 27, 2003 at 01:04 UTC | |
|