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 } }
In reply to Re: How do I parse and evaluate a file line-by-line?
by dfog
in thread How do I parse and evaluate a file line-by-line?
by kendroid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |