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

I have a question....How can I compare two different times' but skip skip any lines that have text? Every 10 seconds a ping is sent out. For any time greater than 10 seconds I want to document that a packet was lost. The file contains headers for every 5 minutes. The problem is that whenever it comes across a header, it makes it look like a packet was lost. Any suggestions? My code is below. Thanks in advance.
foreach my $line (<FILE>) { # Do following for each line infile chomp $line; if ($line =~ /^\b\d/){ # Skip lines that contain text ($timestamp, undef, $out, undef, undef, undef, $in, undef)=split(/\t/, + $line); # Sort out needed columns my $seconds = ($timestamp - $last_time); # Determine elapsed time if ($seconds > .00012){ # For time longer than 10 seconds my $time = DateTime::Format::Excel->parse_datetime($timestamp); # For +mat time/date my $logdate = $time->ymd; # Date format my $logtime = $time->hms; # Time format my $error_name = "$center Error Log $log_time"; open(PACKETS,">> /directory/logs/error_log.txt"); print PACKETS "Packet lost on $logdate at $logtime\n" or die "Can't op +en file $!"; # Write to log file } $last_time = $timestamp; # Store as previous time to compare

Replies are listed 'Best First'.
Re: Skip header text when comparing time
by Osiris1975 (Novice) on Jan 15, 2009 at 20:52 UTC
    It would help if we knew what the header looks like. I think you would want to look for something unique in the header line that does not exist in the other lines. Do you have a sample of the input?
      Here is an example of the headers:

      oau-iperf-sip oau-iperf-sip s-oau-dr0 s-oau-dr0 s-swau-dr0 s-swau-dr0 swau-iperf-sip swau-iperf-sip swau-iperf-sip

      The headers may change, so I want to skip the line of headers completely and only compare the lines with numbers. When it comes across a header, I want it to skip that line but continue to compare the lines with numbers.
        So, I imagine the headers will never have a time in them? Time has a a ":" in it that should be unique to them. So maybe instead of :
        if ($line =~ /^\b\d/)
        You could use
        if ($line =~ m/:/)
        I didn't test it since I don't have a sample of your input, but something along those lines should process your steps only if the lines have a colon in them. Alternatively, if the headers and only the headers contain "perf" in them, you could do
        if ($line !~ m/perf/)