in reply to How do I parse and evaluate a file line-by-line?

Assuming that you read in the file into the array using
@lines = <FILE>;
and that the array is already in chronological order, you could loop through matching downs with ups in the following way:
my $count = -1; # set to -1 for loops sake and autoincrementing my $placeHolder = 0; # remembers place in array for the first down my $totalDownTime = 0; while ( $count++ <= $#lines ) { if ( $lines[$count] =~ /Down/ ) # finds first down; { $placeHolder = $count; # the following while increments until it finds the next up, # or the end of the array while ( ( $count++ <= $#lines ) && ( $lines[$count] =~ /Down/ +) ) { # do nothing in the while loop } $totalDownTime += sum( $lines[$placeHolder], $lines[$count] ); # sum will be a function defined by you that takes the lines w +ith # down and its corresponding up, parses them, # and returns the time difference } }

Replies are listed 'Best First'.
Re: Answer: How do I parse and evaluate a file line-by-line?
by blazar (Canon) on May 03, 2007 at 10:33 UTC
    and that the array is already in chronological order, you could loop through matching downs with ups in the following way:

    The code I snipped below the above quote seems to be aimed at some specific parsing of some specific kind of file, and thus hardly answers the question contained in its own Subject, namely "How do I parse and evaluate a file line-by-line?" Or am I missing something? If not, then isn't this OT?

Re: Answer: How do I parse and evaluate a file line-by-line?
by Anonymous Monk on May 03, 2007 at 01:52 UTC
    When you read data from a file into an array it is already in order. If you want to read the last element of the array then simply use array-1 and then keep incrementing to go from the bottom up. Hope this helps. Shashidhar Iddamsetty
      When you read data from a file into an array it is already in order.

      Yep, the original node said so, too.

      If you want to read the last element of the array then simply use array-1 and then keep incrementing to go from the bottom up.

      Wasn't this basically your other reply too? At least there it made some (i.e. "a very limited amount of") sense. Here, it's completely OT wrt what you're replying to. Which in turn seems to be OT wrt its own subject...

      Hope this helps.

      I don't think so. Sorry.