Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Problems? Is your data what you think it is?
 
PerlMonks  

Re: print problem

by {NULE} (Hermit)
on Dec 21, 2001 at 01:45 UTC ( [id://133699]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to print problem

Hi Punto,

Yes, is the short answer to your question. Here is some code that works:

#! /usr/bin/perl -w use strict; $| = 1; # This forces your selected filehandle (STDOUT # in this case) to be unbuffered. my $i = 0; while (1) { sleep(1); print $i++," - ",$i++," - ",$i++,"\r"; }

There are other ways to do this that might be more elegant or more cross-platform. I believe that looking on CPAN for Term and Curses might be useful to you. (Note to self: finish up that stinking Curses tutorial already...)

Good luck,
{NULE}
--
http://www.nule.org

Replies are listed 'Best First'.
Re: Re: print problem
by hossman (Prior) on Dec 21, 2001 at 02:32 UTC
    The reason you need to set $| is explained in "perldoc perlvar"...
        $|    If set to nonzero, forces a flush right away and
              after every write or print on the currently
              selected output channel.  Default is 0
              ...
              STDOUT will typically be line buffered if output
              is to the terminal and block buffered otherwise.
              ...
    
    So in your orriginal program, the buffer was just building up because it never say a line termination. (and when you switched to "\n" it did).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://133699]
help
Sections?
Information?
Find Nodes?
Leftovers?
    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.