Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Opens but Won't Write to file

by BrowserUk (Pope)
on Oct 30, 2009 at 22:08 UTC ( #804226=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Opens but Won't Write to file
in thread Opens but Won't Write to file

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.


Comment on Re^3: Opens but Won't Write to file
Select or Download Code
Re^4: Opens but Won't Write to file
by ikegami (Pope) on Oct 30, 2009 at 22:16 UTC

    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);
Re^4: Opens but Won't Write to file
by saintjames (Novice) on Oct 30, 2009 at 22:36 UTC

    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-

Re^4: Opens but Won't Write to file
by chromatic (Archbishop) on Oct 31, 2009 at 08:58 UTC
    Simplest, but costly.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://804226]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-12-21 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls