go ahead... be a heretic | |
PerlMonks |
Re: Regex problem while parsing tagged, hierarchical databy mk. (Friar) |
on Sep 12, 2006 at 15:10 UTC ( [id://572556]=note: print w/replies, xml ) | Need Help?? |
hope this helps: perl -i -pe 'if (/<level1 id=\"(.*)\">/) {$currentid = $1;} elsif (/<level2>/) {s/<level2>/<level2 id="$currentid">/g}' input edit: just deleting the redundant $_. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "one who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever." mk at rio dot pm dot org
In Section
Seekers of Perl Wisdom
|
|