in reply to processing columns of text

Think about what you need to do:

  1. loop over the lines
  2. for each line extract the fields
  3. calculate the differences between the required fields
  4. print the result
  5. save the current line as the last line
  6. (you did skip for the first record didn't you?)
use warnings; use strict; my @last; my @current; while (<DATA>) { # For each line chomp; # Strip any trailing line end sequence @current = split; # extract the fields next if ! @last; # Skip for the first line my @diffs = map {$current[$_] - $last[$_]} 2 .. 5; # Calculate print "@current[0, 1, 2] @diffs\n"; # Print } continue { @last = @current; # Save current line as last } __DATA__ 02/02/2007 00:00:00 719267027 719244316 719233953 719240015 02/03/2007 00:00:00 720375777 720336674 720325633 720329849 02/04/2007 00:00:00 721640280 721640267 721522690 721552815 02/05/2007 00:00:00 722297206 722297203 722297203 722297206

Prints:

02/03/2007 00:00:00 720375777 1108750 1092358 1091680 1089834 02/04/2007 00:00:00 721640280 1264503 1303593 1197057 1222966 02/05/2007 00:00:00 722297206 656926 656936 774513 744391

You may care to take a look at the docs for split, map and 'Loop Control' in perlsyn.


DWIM is Perl's answer to Gödel