Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: File contents not updated properly

by sathiya.sw (Monk)
on Dec 09, 2008 at 05:27 UTC ( [id://729091]=note: print w/replies, xml ) Need Help??


in reply to File contents not updated properly

You need to select the file handle as,
select(FH);
open(FH,">Sample"); select(FH); $|=1; while(1) { print FH "This is for testing\n"; sleep 1; }
Sathiyamoorthy

Replies are listed 'Best First'.
Re^2: File contents not updated properly
by fmerges (Chaplain) on Dec 09, 2008 at 18:02 UTC

    Hi,

    First of all, don't assume that you could open the file, check for it. Then use 3 argument open, and don't use a typeglob.

    open my $fh, '>', $filename or die "Can't open $filename: $!";

    The solution provided will leave the default handler to be *FH, which is not desired, meaning all prints, etc will use *FH; alternatives:

    # not so maintainable, but still used frequently select((select($fh), $|++)[0]); # better use IO::Handle; $fh->autoflush(1);

    Check out the link about buffering provided...

    Regards,

    fmerges at irc.freenode.net

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2026-01-19 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (122 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.