<input> <tr><tc>1</tc><tc>2</tc><tc>3</tc></tr> <tr><tc colspan="2">1and2</tc><tc>3</tc></tr> <tr><tc>1</tc><tc colspan="2">2and3</tc></tr> <tr><tc>1</tc><tc>2</tc><tc>3</tc></tr>
My present code produces wrong output:<RequiredOutput> <tr><tc cNum="1">1</tc><tc cNum="2">2</tc><tc cNum="3">3</tc></tr> <tr><tc cNum="1" colspan="2">1and2</tc><tc cNum="3">3</tc></tr> <tr><tc cNum="1">1</tc><tc cNum="2" colspan="2">2and3</tc></tr> <tr><tc cNum="1">1</tc><tc cNum="2">2</tc><tc cNum="3">3</tc></tr>
e.g. in the 2nd row, I am not sure how to increment the column Number cNum based on the previous column span's value.#!/usr/bin/perl open(IN, "<data.in") or die ("inFile not found -- $!\n"); open(OUT, ">data.out") or die ("outFile not found -- $!\n"); while(<IN>) { local $/='<tr>'; my $cnt=0; while(/<tc>/){ s!<tc>!'<tc cNum="'.++$cnt.'">'!ie; } print OUT; } close(IN); close(OUT);
Please give me some tips.
Thanks in advance.
In reply to how to loop through? by texuser74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |