Hi, I have a numbered list marked up with <nl>...</nl>. All items inside it are marked as <item>...</item>. I want to number these items sequentially, i.e., change the item tag to <item num="1">, <item num="2"> and so on. My code to do this is:
$no++;
$_ =~ s/<item>/'<item num="'.$no.'">'/egs;
In the output file I get the desired numbering but from the start to the end of file, the <item> tags are sequentially numbered. I want the count to restart everytime a new list <nl> is encountered. Any help!!!
Here is my complete code:
if (!@ARGV) { print "\t Usage: perl $0 <filename>\n\n"; exit(0); } open (F1, "<$ARGV[0]") || die ("Can't open the file $ARGV[0]. $!\n"); $out = $ARGV[0]; $out =~ s/(.+)\.(.+)/$1/; $out = $out.".xml"; open (F2, ">$out") || die ("Can't open the file $out. $!\n"); while(<F1>) { $no++; $_ =~ s/<item>/'<item num="'.$no.'">'/egs; print F2 $_; } close F1; close F2;
20060801 Janitored by Corion: Removed by-line <code> tags and enclosed code within one set of <code>...</code> tags
In reply to Numbering list items by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |