Anish Kumar K. wrote:
> Hi
> 
> This program I use to get the last line from the log file "cipe.log".
> and then write the line onto a text file "a.txt" 
> 
> system("tail -1 cipe.log > a.txt");
> open INPUT,"a.txt";
> my $line=<INPUT>;
> 
> then I open the text file and read the value from the file handle.
> 
> This invloves cumbersome process. I need to avoid writing to a file
> the o/p of the system command. Is there a way to assign to some
> variable...  

Backticks capture output:

   my $line = `tail -1 cipe.log`;

Tie::File is also easy, and portable to systems without tail(1):

   use Tie::File;
   tie @arr, 'Tie::File', 'cipe.log' or die $!;
   my $line = @arr[-1];

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