What I think you are saying is that you are searching  a log file for an
error. If you find an error, you want to print out the last 10 lines (that
would be the error line and The previous 9 lines) and the next 10 lines
(total of 20 lines). Is this correct? You have to state the entire problem
more clearly including data an examples.

The following code accomplishes the statement above. You have to modify
DoChat() to print the values in @tail. The following code finds the first
/error/, populates @tail and prints it to the screen then exits. You have to
add in seek() and tell() so that the process does not exit until the end of
the log file. If the process never ends you have to continue to open the log
file and seek to the place you last read from then continue.

------------------
#!/usr/bin/perl
use warnings;
use strict;

my @tail;
open LOG, 'logfile.txt' or die "Could not open log file: $!";

while (<LOG>) {
  push @tail, $_;
  shift @tail if @tail > 10;
  if (/error/) {
    my($line, $count);
    while (defined($line = <LOG>) and ++$count <= 10) {
      push @tail, $line;
    }
    # do not last here, instead DoChat() then clear out @tail
    # seek() to last position and continue
    last;
  }
}

print $_ foreach @tail;



"Sreedhar Kalkunte-Venkatachala" <[EMAIL PROTECTED]>
wrote in message
news:[EMAIL PROTECTED]
hi

This program will be keep running in background like tail -f .

that moment y find error it will capture and last 10 lines and next 10 lines
and prints into the chat board. so while printing I want it as single
variable. so, it will fast(one connection)

regards
Sreedhar




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to