I have data files in text format which have several rows. Now there are certain rows that have wrong data which I need to update with those that have the correct data. For example,
Col1 Col2 Col3 Col4 .......
A1?% A foo fooo .......
B€(2 B .................
C&6 Z .................
A?04 Y .................
B++3 Q .................
C!5 C .................
D*9 D .................
The actual data is different but this is a simplified version of it. As you can see there are certain Col1 where A1 is A but A4 is Y and so on. The rest of the columns Col3, Col4 ... depend on Col2. So, I need to check if Col2 is A when there is an A in Col1 (A1, A2, A3 etc). If not I have to update Col2, Col3 .... based on the row where it is A.
How may this be accomplished in Perl. I know this kind of operations can be done in an database with an update statement but I don't have that luxury here and have to do it programatically.
Edit: The files are tab delimited and the data are strings that can contain any alphanumeric or ascii character.
The way I would do this is to open an input file handle and an output file handle, and go line by line through the file checking column one and, if its fine, just plop it into my output just as it is.
If it does need to change, I would make a new line with the necessary changes and put it into my output file as well.
This is a simple approach, that while not the greatest/elegant/whatever, would give you what you need quickly.