<[EMAIL PROTECTED]> wrote: > > I have some data column based data I want to modify a bit. > > 0065 663 517 046 0 1485 > 0065 663 517 046 3 1500 > 0065 663 517 046 5 1882 > 0120 620 515 919 0 1485 > 0120 620 515 919 6 1816 > 0120 620 515 919 8 2136 > > I would like to add a counter to column 5 to fill out the gaps > in between e.g. 0 and 10 - but doing so without changing the > other columns values until column 4 itself changes values > > My result would look like: > 0065 663 517 046 0 1485 > 0065 663 517 046 1 1485 > 0065 663 517 046 2 1485 > 0065 663 517 046 3 1500 > 0065 663 517 046 4 1500 > 0065 663 517 046 5 1882 > 0120 620 515 919 0 1485 > 0120 620 515 919 1 1485 > 0120 620 515 919 2 1485 > 0120 620 515 919 3 1485 > 0120 620 515 919 4 1485 > 0120 620 515 919 5 1485 > 0120 620 515 919 6 1816 > 0120 620 515 919 7 1816 > 0120 620 515 919 8 1485 > > My initial idea was to compare (in a while loop) the value in > column 4 with the previous line. However, I cannot figure out > how to save the "comparing" variable. > > Any ideas how to get started on this? > Thanks
I think the program below will do what you want. Cheers, Rob use strict; use warnings; my @last_data; while (<DATA>) { my @data = split; if (@last_data and $last_data[3] == $data[3]) { while (++$last_data[4] < $data[4]) { printf "%04d %03d %03d %03d %2d %04d\n", @last_data; } } printf "%04d %03d %03d %03d %2d %04d\n", @data; @last_data = @data; } __DATA__ 0065 663 517 046 0 1485 0065 663 517 046 3 1500 0065 663 517 046 5 1882 0120 620 515 919 0 1485 0120 620 515 919 6 1816 0120 620 515 919 8 2136 **OUTPUT** 0065 663 517 046 0 1485 0065 663 517 046 1 1485 0065 663 517 046 2 1485 0065 663 517 046 3 1500 0065 663 517 046 4 1500 0065 663 517 046 5 1882 0120 620 515 919 0 1485 0120 620 515 919 1 1485 0120 620 515 919 2 1485 0120 620 515 919 3 1485 0120 620 515 919 4 1485 0120 620 515 919 5 1485 0120 620 515 919 6 1816 0120 620 515 919 7 1816 0120 620 515 919 8 2136 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]