Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Opens but Won't Write to file

by MidLifeXis (Monsignor)
on Oct 30, 2009 at 21:30 UTC ( #804221=note: print w/replies, xml ) Need Help??

in reply to Opens but Won't Write to file

  • Setting autoflush ($|=1) is not being done on OUTFIL. See select.
  • close(OUTFIL) will never be reached due to the while (1) {...}.
With those items, it is possible that your output buffer is just not full, so the data is never flushed to disk. Add that to Joost's exhortations, and see what you come up with.


Replies are listed 'Best First'.
Re^2: Opens but Won't Write to file
by ikegami (Pope) on Oct 30, 2009 at 21:49 UTC
    Ignore select. The simplest way to turn off buffering on a handle is
    use IO::Handle qw( ); HANDLE->autoflush(1);

      Simplest, but costly. From the docs:

      use IO::Handle; # thousands of lines just for autoflush :-(

      I think that comment originates from someone rather well respected within the perl community.

      That could be avoided by a simple (untested):

      sub autoflush{ my $old = select $_[ 0 ]; $|=1; select $old; } ... autoflush $fh;

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Actually, the OP already has IO::Handle loaded (via IO::Socket via IO::Socket::INET), so it's free for him.

        For others, it has a one-time cost of 100ms.

        >perl -le"use Time::HiRes qw( time ); $stime=time; require IO::Handle; + $etime=time; print $etime-$stime;" 0.082003116607666 >perl -le"use Time::HiRes qw( time ); $stime=time; require IO::Handle; + $etime=time; print $etime-$stime;" 0.0974130630493164 >perl -le"use Time::HiRes qw( time ); $stime=time; require IO::Handle; + $etime=time; print $etime-$stime;" 0.120858192443848

        It's up to them if that's acceptable or not. If it's not, I suggest copying autoflush out of IO::Handle and call it as follows rather than twiddling with select and $| directly.

        autoflush(HANDLE, 1);
        Simplest, but costly.

        What kind of use do you have for a UDP server where the overhead of loading IO::Handle is even measurable?

        Okay, thank you all for your kind notations. I have made a couple ssmall changes, doing the 'Standard' thing with Open OR Die and then using Select and autoflush($|=1); Thanks again to all Jim-

      Aaah, yes. Old habits (this is a monastery, after all) die hard. I guess I need to update that habit.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://804221]
[LanX]: YAPC Asia was renamed and you'd need to speak Japanese to be able to follow
[robby_dobby]: LanX: Misery :P
[robby_dobby]: Or India
LanX which means I can finally organize YAPC Asia in Sharm el Sheikh ;-)
[robby_dobby]: I attended a couple conferences (both in India). Left me with a renewed enthusiasm to do more, only to see it disappear in a few days!
[LanX]: Then come to YAPC EU in Amsterdam ...
[robby_dobby]: LanX: But that's in Africa! More like YAPC::Africa
choroba fears Amsterdam might fill him with enthusiasm to do nothing
[robby_dobby]: Uff, too expensive :-(
[LanX]: ... I found YAPC EU more entertaining (and international )than YAPC NA

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-04-24 15:57 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.