in reply to system call: Unix system call result into a variable

Try:

my $MSG = `tail -n 10 $ERRLOG`;

but really you ought to consider using something like File::Tail to do the job instead.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: system call: Unix system call result into a variable
by runrig (Abbot) on Jul 17, 2007 at 22:11 UTC
    File::Tail is more for "tail -f" functionality, where you want to keep reading from a continuously updated (i.e. appended to) file. Using backticks (as in your example) or qx is a perfectly acceptable (and simple, efficient) solution.
      File::Tail may be used like a conventional tail(1) - without the rescan - by specifying the 'tail' argument to the constructor. However to prevent the 'wait' you have to only display those lines you ask for (then destroy the object). For example:
      use strict; use File::Tail; my $num_of_lines = 10; my $tail = new File::Tail (name=>$ERRLOG, tail => $num_of_lines); for (1..$num_of_lines) { my $line = $tail->read(); print "$_: $line"; } $tail = undef;

      update: I emailed the author of File::Tail (Matija Grabnar) with this solution, and he was kind enough to respond immediately with the following:
      "You're wasting most of File::Tails potential, but yes, that should work.
      Note that it won't work if your input is a stream or a pipe (for which ordinary tail would work)."