-4

For example: 32.44 and 30.97 then 30.97 and 29.77 so on for n number for using perl

Col1      Col2   Col3    Col4
------------------------------
0000     32.44   37.88   39.47
0001     30.97   37.87   39.49
0002     29.77   37.69   39.39
0003     28.26   37.43   39.23
Håkon Hægland
  • 32,521
  • 18
  • 64
  • 139

1 Answers1

1

Store the value in a variable outside the loop in order to access it in the subsequent pass of the loop.

my $previous;
while (<>) {
   next if $. < 3;  # Skip the header.

   my @fields = split;
   say $fields[1] - $previous if defined($previous);
   $previous = $fields[1];
}
ikegami
  • 322,729
  • 15
  • 228
  • 466