Try something like this:

#! perl -slw use strict; use threads; use Thread::Queue; $|=1; sub tail { my( $file, $Q ) = @_; my $pid = open TAIL, "u:tail --follow=name $file |" or die $!; print "pid:$pid"; END{ kill 9, $pid } while( <TAIL> ) { $Q->enqueue( $_ ); } } my $Q = new Thread::Queue; my $t = threads->new( \&tail, $ARGV[ 0 ], $Q ); while( sleep 1 ) { print 'Here'; printf "Got: %s", $Q->dequeue() while $Q->pending; }

Sample output

## Create a file to tail P:\test>start /b perl -le"$|=1; select( undef, undef, undef, 0.1 ), pr +int $_, '-'x100 for 1 .. 10000;" > tmp\log P:\test>387706 tmp\log pid:276 Here Here Here Here Got: 11--------------------------------------------------------------- +------------------------------------- Got: 12--------------------------------------------------------------- +------------------------------------- Got: 13--------------------------------------------------------------- +------------------------------------- Got: 14--------------------------------------------------------------- +------------------------------------- Got: 15--------------------------------------------------------------- +------------------------------------- Got: 16--------------------------------------------------------------- +------------------------------------- Got: 17--------------------------------------------------------------- +------------------------------------- Got: 18--------------------------------------------------------------- +------------------------------------- Got: 19--------------------------------------------------------------- +------------------------------------- Got: 20--------------------------------------------------------------- +------------------------------------- Got: 21--------------------------------------------------------------- +------------------------------------- Got: 22--------------------------------------------------------------- +------------------------------------- Got: 23--------------------------------------------------------------- +------------------------------------- Got: 24--------------------------------------------------------------- +------------------------------------- Got: 25--------------------------------------------------------------- +------------------------------------- Got: 26--------------------------------------------------------------- +------------------------------------- Got: 27--------------------------------------------------------------- +------------------------------------- Got: 28--------------------------------------------------------------- +------------------------------------- Got: 29--------------------------------------------------------------- +------------------------------------- Got: 30--------------------------------------------------------------- +------------------------------------- Got: 31--------------------------------------------------------------- +------------------------------------- Got: 32--------------------------------------------------------------- +------------------------------------- Got: 33--------------------------------------------------------------- +------------------------------------- Got: 34--------------------------------------------------------------- +------------------------------------- Got: 35--------------------------------------------------------------- +------------------------------------- Got: 36--------------------------------------------------------------- +------------------------------------- Got: 37--------------------------------------------------------------- +------------------------------------- Got: 38--------------------------------------------------------------- +------------------------------------- Got: 39--------------------------------------------------------------- +------------------------------------- Got: 40--------------------------------------------------------------- +------------------------------------- Got: 41--------------------------------------------------------------- +------------------------------------- Got: 42--------------------------------------------------------------- +------------------------------------- Got: 43--------------------------------------------------------------- +------------------------------------- Got: 44--------------------------------------------------------------- +------------------------------------- Got: 45--------------------------------------------------------------- +------------------------------------- Got: 46--------------------------------------------------------------- +------------------------------------- Got: 47--------------------------------------------------------------- +------------------------------------- Got: 48--------------------------------------------------------------- +------------------------------------- Got: 49--------------------------------------------------------------- +------------------------------------- Here Here Here Here Got: 50--------------------------------------------------------------- +------------------------------------- Got: 51--------------------------------------------------------------- +------------------------------------- Got: 52--------------------------------------------------------------- +------------------------------------- Got: 53--------------------------------------------------------------- +------------------------------------- Got: 54--------------------------------------------------------------- +------------------------------------- Got: 55--------------------------------------------------------------- +------------------------------------- Got: 56--------------------------------------------------------------- +------------------------------------- Got: 57--------------------------------------------------------------- +------------------------------------- Got: 58--------------------------------------------------------------- +------------------------------------- Got: 59--------------------------------------------------------------- +------------------------------------- Got: 60--------------------------------------------------------------- +------------------------------------- Got: 61--------------------------------------------------------------- +------------------------------------- Got: 62--------------------------------------------------------------- +------------------------------------- Got: 63--------------------------------------------------------------- +------------------------------------- Got: 64--------------------------------------------------------------- +------------------------------------- Got: 65--------------------------------------------------------------- +------------------------------------- Got: 66--------------------------------------------------------------- +------------------------------------- Got: 67--------------------------------------------------------------- +------------------------------------- Got: 68--------------------------------------------------------------- +------------------------------------- Got: 69--------------------------------------------------------------- +------------------------------------- Got: 70--------------------------------------------------------------- +------------------------------------- Got: 71--------------------------------------------------------------- +------------------------------------- Got: 72--------------------------------------------------------------- +------------------------------------- Got: 73--------------------------------------------------------------- +------------------------------------- Got: 74--------------------------------------------------------------- +------------------------------------- Got: 75--------------------------------------------------------------- +------------------------------------- Got: 76--------------------------------------------------------------- +------------------------------------- Got: 77--------------------------------------------------------------- +------------------------------------- Got: 78--------------------------------------------------------------- +------------------------------------- Got: 79--------------------------------------------------------------- +------------------------------------- Got: 80--------------------------------------------------------------- +------------------------------------- Got: 81--------------------------------------------------------------- +------------------------------------- Got: 82--------------------------------------------------------------- +------------------------------------- Got: 83--------------------------------------------------------------- +------------------------------------- Got: 84--------------------------------------------------------------- +------------------------------------- Got: 85--------------------------------------------------------------- +------------------------------------- Got: 86--------------------------------------------------------------- +------------------------------------- Got: 87--------------------------------------------------------------- +------------------------------------- Got: 88--------------------------------------------------------------- +------------------------------------- Here Here Terminating on signal SIGINT(2)

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re: Piping Tail and while loops by BrowserUk
in thread Piping Tail and while loops by matt.schnarr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.