in reply to How do I parse and evaluate a file line-by-line?
The idea here is to record just the last "UP" or "DOWN" event in a string of one or more "UP" or "DOWN" events. $cursor is used to keep our place in the array, overwritting successive UP's and DOWN's as necessary.#!/usr/bin/perl -w use strict; my $last = ""; my $cursor = -1; my @output; while (<DATA>) { my ($time, $switch) = split "\t"; if ($switch eq $last) { $output[$cursor] = $_; } else { $cursor++; $output[$cursor] = $_; $last = $switch; } } foreach (@output) { print; } __DATA__ time1 UP time2 DOWN time3 UP time4 DOWN time5 DOWN time6 DOWN time7 UP time8 UP time9 UP time10 DOWN time11 UP
Gary Blackburn
Trained Killer
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do I parse and evaluate a file line-by-line?
by merlyn (Sage) on Mar 03, 2001 at 20:47 UTC | |
by Trimbach (Curate) on Mar 03, 2001 at 20:57 UTC |