Unable to flush o/p buffer

Discussion in 'Perl Misc' started by myflaneur@yahoo.com, Jun 13, 2006.

  1. Guest

    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]);
    }

    ---------------------------------
    , Jun 13, 2006
    #1
    1. Advertising

  2. Anno Siegel Guest

    wrote:

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

    > -------------------------------------------------------
    > open(OUTPUT,">>my_output.txt");
    > #within some loop


    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
    Anno Siegel, Jun 13, 2006
    #2
    1. Advertising

  3. Guest

    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 Siegel wrote:
    > wrote:
    >
    > > 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.
    >
    > > -------------------------------------------------------
    > > open(OUTPUT,">>my_output.txt");
    > > #within some loop

    >
    > 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
    , Jun 13, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian

    Response.Buffer and Resonse.Flush

    Brian, Nov 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,419
    Scott M.
    Nov 22, 2003
  2. Matthias Straka

    Minimum buffer length for Response.Flush?

    Matthias Straka, Sep 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    584
    Matthias Straka
    Sep 9, 2004
  3. Kiran

    socket buffer flush question

    Kiran, Jul 5, 2006, in forum: Python
    Replies:
    2
    Views:
    973
    Jim Segrave
    Jul 5, 2006
  4. mike
    Replies:
    0
    Views:
    373
  5. Replies:
    1
    Views:
    1,917
Loading...

Share This Page