I need to do the following find and replace. i.e. need to fill in the 'refid' by matching the 'label' text. Unfortunately my script is producing unexpected outputs. pls review
Input:
<crossRef refid="">xx</crossRef>
<crossRef refid="">yy</crossRef>
<affiliation id="aff01"><label>xx</label>
<affiliation id="aff02"><label>yy</label>
Output:
<crossRef refid="aff01">xx</crossRef>
<crossRef refid="aff02">yy</crossRef>
<affiliation id="aff01"><label>xx</label>
<affiliation id="aff02"><label>yy</label>
my code:
if (/<affiliation id="(.+?)"><label>(.+?)<\/label>/)
{
$affid=$1; $afflbl=$2;
s!<crossRef refid="(.*?)">$afflbl</crossRef>!<crossRef refid="$a
+ffid">$afflbl</crossRef>!g;
}
my code is not working properly. please suggest me the correct way of doing it.