Hi thank you very much for the mail. but just tme how store
print $_ foreach @tail; this in a variable. So when I do DoChat($variable). it will print the complete information in one shot. Regards Sreedhar -----Original Message----- From: Zeus Odin [mailto:[EMAIL PROTECTED] Sent: 23 October 2004 13:49 To: Kalkunte-Venkatachala, Sreedhar; [EMAIL PROTECTED] Subject: RE: How to store the out put in StringBuffer This is a *quick* emulation of tail. Emphasis on quick as in quickly done. If you want to return only lines that match a regular expression, add the line: next unless /$regexp/; Immediately after while (<>) { It seems like you have DoChat() under control. Good luck, ZO ------------------------ #!/usr/bin/perl use warnings; use strict; # This emulates tail # # prompt> tail.pl 15 logfile.txt file2.txt file3.txt .... # or # prompt> tail.pl logfile.txt .... my $lines = $ARGV[0] =~ /^\d+$/ ? shift : 10; my @tail; while (<>) { push @tail, $_; shift @tail if @tail > $lines; if (eof) { print "\n$ARGV:\n"; print $_ foreach @tail; } } -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, October 23, 2004 7:32 AM To: [EMAIL PROTECTED] Subject: RE: How to store the out put in StringBuffer Hi Basically I have written a program similar to tail -f. System will search for error message. If found it has to through to chat channel. Problem is it connects to chat channel to print each line. I want to store in a variable and print at one shot. How to do this? Kindly let me know ========================== open (LOGFILE,"$FILENAME"); for (;;) { for ($cursorposition = tell(LOGFILE); $_ = <LOGFILE>; $cursorposition = tell(LOGFILE)) { $line = $_; chomp $line; push @buffer, $line; if (@buffer > 10) { shift @buffer; } if ($line =~/$regex/) { $j = 0; foreach $previousLine (@buffer) { $j++; $msg=$previousLine; } $i = 0; $pos = tell LOGFILE; while(<LOGFILE>) { $i++; if ($i > 10) { last; } $var = $_; $msg=$var; } DoChat($msg); seek(LOGFILE, $pos, 0); } } sleep(1); seek(LOGFILE, $cursorposition, 0); } ==================================================================== -----Original Message----- From: Zeus Odin [mailto:[EMAIL PROTECTED] Sent: 23 October 2004 12:29 To: Kalkunte-Venkatachala, Sreedhar Subject: Re: How to store the out put in StringBuffer First, always use warnings; use strict; at the top of each program you write. Second, what are you trying to do exactly? Third, some observations: 1) You use $j and $pos exactly one time. Why are they present? 2) You seem to be looping to 10 using $i. Why not instead use for my $i(1 .. 10) { code here } 3) What are you trying to do with <LOGFILE>? It seems to me that you are printing each item in @buffer, then printing the next 10 lines of LOGFILE. Is this what you are trying to do? Are @buffer and LOGFILE related at all? Thanks, ZO "Sreedhar Kalkunte-Venkatachala" <[EMAIL PROTECTED]> wrote... Hi Say I have program like this If I Say print It prints each line. How to store the both output in one string buffer ($previousLine and $var) For example I have written this program ======================================== foreach $previousLine (@buffer) { $j++; print "$previousLine"; } $i = 0; $pos = tell LOGFILE; while(<LOGFILE>) { $i++; if ($i > 10) { last; } $var = $_; print $var; } ======================================== Regards Sreedhar Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>