Jim Gibson <jimsgib...@gmail.com> writes:

> At 3:57 PM -0500 10/24/09, Harry Putnam wrote:
>>Sorry about being tricky with what was an older thread.  But I suspect
>>that thread died... and no one noticed there was an unaswered question
>>still there.

> Or no one knew the answer.

He he... unlikely here I think..

[...]

> I would modify the above a little. You are calling eof after each
> line, which is unnecessary. The input operator <FILE> will return
> undef whenever eof will return true, so calling eof is redundant. You
> can make this a little more efficient with something like the
> following (untested):
>
>   while(1) {
>     while(<FILE>) {
>       print;
>     }
>     sleep 1;
>     seek(FILE,0,1);
>   }
>

That does look like it might be better... and thanks for the explanation.

[...]

>>
>>   use File::Tail;
>>   $file=File::Tail->new("/some/log/file");
>>   while (defined($line=$file->read)) {
>>       print "$line";
>>   }
>
> That looks OK, and works for me on /var/log/system.log, although the
> delays are longer using File::Tail than Unix tail. Maybe you should

That isn't actually the version I used .. its a bit lower on the page
you cited above... but I can't see anything that make it work any
different. 

cat fltr_sl

[...]

  use File::Tail;

  my ($file,$line);
  my $fname_in = "/var/adm/slpipe";

  $file=File::Tail->new("$fname_in");
  while (defined($line=$file->read)) {
     print "$line";
  }  

> try it on a normal file that you write to occasionally with another
> Perl program.

One question, in your test you didn't actually run it against a
named-pipe did you?  Would that be likely to make a difference?

Taking your suggestion I see the script above will ouput from a normal
file.

touch t1

./filterWithFileTail.pl (edited to open ./t1)

while [[ 1 ]];do
 echo "Now you've done it" >> t1
sleep 1
cat ~/.bash_history >> t1
sleep 1
done

The File::Tail filter does eventually output the data coming in.  You
mentioned it's slower.. it seems a good bit slower here.

But it will NOT ouput data from the named pipe.

I ran the same while loop writing to the named pipe and still the perl
filter with File::Tail won't output a thing.

Anyway I have a working script... soon to modify with your
suggestions. .. thanks for the help.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to