good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Determine new line number in revised file given old line numberby ExReg (Priest) |
on Mar 29, 2017 at 18:23 UTC ( [id://1186417]=perlquestion: print w/replies, xml ) | Need Help?? |
ExReg has asked for the wisdom of the Perl Monks concerning the following question: I have a file that lists thousands of lines of interest in a large baseline of code. Each line will list the module and line number. When I get an updated list of lines at a later date, becasue of changes to the baseline, some lines will stay the same, there will be some new lines, there will be some lines that go away, and some lines will have their line number change. If a module has a line inserted into it or deleted between the two times, the line number of interest will be different. Without doing a diff on the two files, it is difficult to tell whether that changed line listing is due to a line number change or if there was a deletion and insertion. Since I have thousands of lines tracked, doing manual diffs is not an option. So I wrote a Perl script to automate the process. I can give it the old module, the updated module, and the line number of interest. It will give me what that line number would be in the new module, or 0 if it is no longer there or changed. That way I can tell if it was a line number change, or an addition plus deletion instead. It does a diff on the two files, then uses the n1an2 or n1,n2cn3 or whatever lines diff gives to get an array of new to old line numbers. I then have to reverse that array into another to get the old to new line numbers. Only then can I use the line number as an index to that array to get the line number in the updated module. Has anyone had to do something similar? It seems a little convoluted. Is there an easier way to determine what the new line number would be in a modified file? ( I hope I copied my listing correctly. )
Back to
Seekers of Perl Wisdom
|
|