piping and backgroud processes (daemons)

Hello to all,
I've a strage problem here:
a perl script that parses the output of sar -q 300 0 (one line of performace data each 5 min. infinately) works fine from the CLI. It processes one line output every 5 minutes.
If i disconnect it from the terminal (executing it with cron, nohup startporc etc...) no output is processed until sar has completed (using sar -q 1 20).
then all 20 llines output are processed at the same time.

Code

the script is supposed to run as "demon" in the backdround to ubdate
performance reports every 5 minutes, so i need to process the output just in time.

As far as i foun out it is not a Perl problem rather than the way linux handels pipes on processes not running on a terminal.

any ideas ?

What you are looking for is to set $| = 1; on the currently selected file handle (by default STDOUT). $| also known as $OUTPUT_AUTOFLUSH and also $AUTOFLUSH turns OFF buffering when set and so you will see the results of every print as it happens instead of when perl figures it's time to flush the output buffer. Buffering is ON in perl by default. If you are printing to STDOUT you have only to do a $| = 1; somewhere before your while loop. If you print to some other handle be sure to select(HANDLE); before you assign to $|, etc.

works fine thx.