kevester has asked for the wisdom of the Perl Monks concerning the following question:

I need to write some perl code that will compare line 1 with line 2, then compare line 2 with ilne 3 etc. I tried the following:
while (my $timeOne = <INPUTFILE>) { my $timeTwo =<INPUTFILE>; print OUTPUTFILE "timeOne: $timeOne"; print OUTPUTFILE "timeTwo: $timeTwo"; my $result = $timeTwo - $timeOne; print OUTPUTFILE "result = $result \n"; }
But this will compare line 1 against line 2 and then line 3 against line 4.

Replies are listed 'Best First'.
Re: compare subsequent lines
by moritz (Cardinal) on Jul 14, 2009 at 15:35 UTC
    Please read Writeup Formatting Tips and update your post with proper markup. Thank you.

    What you can do something along these lines:

    my $previous = <IN>; while (<IN>) { # compare $_ and $previous here $previous = $_; }
      Thanks Moritz that works great