If you want to print to a handle, you must 
  print CHAT "text";
If all of your text is in @tail, you can
  print CHAT join '', @tail;
If you still want to print $var for some reason
  my $var = join '', @tail;
  print CHAT $var; 

Does that make sense?

Please read:
perldoc -f join
Perldoc -f print

-ZO

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Saturday, October 23, 2004 10:53 AM
To: [EMAIL PROTECTED]
Subject: RE: How to store the out put in StringBuffer

Hi

Thank you very much for the mail.

at least can you tel me how to store in one variable called $var  (the
result of print $_ foreach @tail;).

because I can print the complete output in one shot.

Regards
Sreedhar

-----Original Message-----
From: Zeus Odin [mailto:[EMAIL PROTECTED]
Sent: 23 October 2004 14:36
To: Kalkunte-Venkatachala, Sreedhar
Subject: Re: How to store the out put in StringBuffer


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;





-- 
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