Unable to flush o/p buffer

M

myflaneur

Hi:

I have been trying to get my PERL script to flush the output buffer
after each and every print statement. I have tried the following code
snippets-none of which are working.

Any help/pointers will be greatly appreciated.

Thanks.

-------------------------------------------------------
open(OUTPUT,">>my_output.txt");
#within some loop
{
$cfh=select OUTPUT;

$|=1;

print OUTPUT "Some array";
select $cfh;

#$cfh->flush();

#select(( select(OUTPUT), $|=1)[0]);
}

--------------------------------

use IO::Handle;
open(OUTPUT,">>my_output.txt");
#within some loop
{
print OUTPUT "Some array";
#OUTPUT->autoflush(1);

#select(( select(OUTPUT), $|=1)[0]);
}

---------------------------------
 
A

Anno Siegel

Hi:

I have been trying to get my PERL script to flush the output buffer
after each and every print statement. I have tried the following code
snippets-none of which are working.

How do you know it isn't working? What do you expect and what does
it do instead?
Any help/pointers will be greatly appreciated.

You're doing much too much in your program(s). It is enough to
set $| = 1 once, there is no need to do that in a loop. Also,
autoflushing is an alternative to calling flush() manually, it doesn't
make sense to do both.

Take it out of the loop. Once is enough.
{
$cfh=select OUTPUT;

$|=1;

print OUTPUT "Some array";
select $cfh;

#$cfh->flush();

#select(( select(OUTPUT), $|=1)[0]);

Why are you doning this *twice* per loop?
}

--------------------------------

use IO::Handle;
open(OUTPUT,">>my_output.txt");
#within some loop
{
print OUTPUT "Some array";
#OUTPUT->autoflush(1);

#select(( select(OUTPUT), $|=1)[0]);
}

---------------------------------

Anno
 
M

myflaneur

Hi:

Thanks for the response.

I am trying to read data from a file, parse the data, and print it out
into another file. The while loop reads the data. I am expecting to
see the output file grow as time progresses and also for the parsed
data to be saved in case of abnormal termination of the script.

After trying out several flavors of the flush command-I could not see
either the output files growing (on checking every 3 minutes) nor the
buffer being saved on a Ctrl-z.

Thanks.


Anno said:
Hi:

I have been trying to get my PERL script to flush the output buffer
after each and every print statement. I have tried the following code
snippets-none of which are working.

How do you know it isn't working? What do you expect and what does
it do instead?
Any help/pointers will be greatly appreciated.

You're doing much too much in your program(s). It is enough to
set $| = 1 once, there is no need to do that in a loop. Also,
autoflushing is an alternative to calling flush() manually, it doesn't
make sense to do both.

Take it out of the loop. Once is enough.
{
$cfh=select OUTPUT;

$|=1;

print OUTPUT "Some array";
select $cfh;

#$cfh->flush();

#select(( select(OUTPUT), $|=1)[0]);

Why are you doning this *twice* per loop?
}

--------------------------------

use IO::Handle;
open(OUTPUT,">>my_output.txt");
#within some loop
{
print OUTPUT "Some array";
#OUTPUT->autoflush(1);

#select(( select(OUTPUT), $|=1)[0]);
}

---------------------------------

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top