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

linux expert wrote:
>>>  Try adding the following line after your 'use warnings' line:
>>>  $|++;
>>>
>>>  That will disable output buffering on the currently-selected
>>>  filehandle (STDOUT be default).

Harry replied:
>>Doesn't appear to make any difference whatever.

Jim G.  added:
> You need to select the logger file before executing $|++:
>
> select LOGNAME;
> $|++;
> select STDOUT;
>
> See the advice given by 'perldoc -q flush' "How do I flush/unbuffer an
> output filehandle?

Thanks, that works fine.

The page offered by perldoc -q flush mentions a write up about
buffering ( http://perl.plover.com/FAQs/Buffering.html ), that I also
went through.

I'm sorry to say that it was mostly like trying to read ancient
sanskrit, since its written in OOPese.  Something I have yet to be
able to look at and have any clue at all about what it means or is
doing. 

But I saw mention of:

  If you're using the FileHandle or IO modules, there's a simpler interface:

        $filehandle->flush();         # Flush the buffer

  It does just the same as the code above. 

So looked at IO::Handle for quite a while and finally noticed near the
bottom some thing I could almost understand.

I experimented quite a bit and ended up with either your suggestion or
or using IO::Handle like so:

   open my( $io_fh ), ">", "$logdir/$logname" 
          or die "Can't open $logdir/$logname: $!";
   $io_fh->autoflush(1);

I wondered if there would be any difference in performance between
using your suggestion:

> select LOGNAME;
> $|++;
> select STDOUT;

or calling in the module,IO::Handle like in the full script below?

In the course of a days run, there would be a whole lot of calls to
print immediately instead of buffer what appears to be 4096 bytes
before writing to log.

If I left any flushing out altogether, I guess it would mean there
would be

  (($TIMERUN * $lines_read_per_second ) / 4096) 

less calls to write to log.  

So considering I'm asking perl to work a lot harder; would either
of the techniques be better performance wise, ?

I can't really think of a way to quickly tell.

------- 8< snip ---------- 8< snip ---------- 8<snip ------- 

#!/usr/local/bin/perl

use strict;
use warnings;
use IO::Handle;

my $logdir ='/var/adm/log';
my $logname = 'pipe1.log';
my $ucsb = qr/ucsb/;
my $temp_thresh =qr/Temperature above Threshold/;
my $hddtemp = qr/hddtemp/;

open my( $io_fh ), ">", "$logdir/$logname" 
          or die "Can't open $logdir/$logname: $!";
$io_fh->autoflush(1);

while(<>){
  if (/$ucsb|$temp_thresh|$hddtemp/){
    print $io_fh $_;
    print $_;
  }
}


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