rsriram has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have tag, which needs to be sequentially numbered. The text goes like this...
<exm>This is example 1 <exm>This is example 2 <exm>This is example 3 <exm>This is example 4
I need to number the <exm> element sequentially until they are sequential.
<exm num="1">This is example 1 <exm num="2">This is example 2 <exm num="3">This is example 3 <exm num="4">This is example 4
If the same set of elements appear in a different part of the text, the number needs to restart.
The code I wrote to achieve is:
I have the content stored in $_. I don't know why, but I am not able to get the numbers reset if the line does not encounter a <exm> tag. Can anyone help me out?$_ =~ s/<exm>/'<exm num="'.$exmno++.'">'/egs; if ($_ != /<exm>/g) {$exmno=0}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Restarting counters in text
by davorg (Chancellor) on Aug 10, 2006 at 11:16 UTC | |
|
Re: Restarting counters in text
by rodion (Chaplain) on Aug 10, 2006 at 12:28 UTC | |
|
Re: Restarting counters in text
by Jasper (Chaplain) on Aug 10, 2006 at 11:27 UTC | |
by udinakar (Novice) on Aug 10, 2006 at 11:35 UTC | |
by davorg (Chancellor) on Aug 10, 2006 at 11:39 UTC | |
by udinakar (Novice) on Aug 10, 2006 at 11:45 UTC | |
|
Re: Restarting counters in text
by Moron (Curate) on Aug 10, 2006 at 11:37 UTC | |
|
Re: Restarting counters in text
by sh1tn (Priest) on Aug 10, 2006 at 13:16 UTC |