in reply to How do I parse and evaluate a file line-by-line?
and that the array is already in chronological order, you could loop through matching downs with ups in the following way:@lines = <FILE>;
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 | |
|
Re: Answer: How do I parse and evaluate a file line-by-line?
by Anonymous Monk on May 03, 2007 at 01:52 UTC | |
by blazar (Canon) on May 03, 2007 at 10:29 UTC |