Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

How to dynamically update value in STDOUT?

by bowei_99 (Friar)
on Nov 05, 2007 at 01:38 UTC ( [id://648935]=perlquestion: print w/replies, xml ) Need Help??

bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:

How can I dynamically update a value on STDOUT? I have a value that uses File::Tail to parse a log and return a valu each time, which is working. The idea is that it gives the user a realtime summary status of the application. However, when displaying the results, I don't really need to show a history of values, only the current value on STDOUT. In other words, instead of printing out the following as a string:

1 3 10 20

it should print 1, then replace that with a 3, then replace that with a 10, then with 20, as it parses the file and determines the value.

I had thought that using

use IO::Handle; *STDOUT->autoflush();
would work, but it seems to be for something else. What is the suggested way of doing this?

-- Burvil

Replies are listed 'Best First'.
Re: How to dynamically update value in STDOUT?
by Sidhekin (Priest) on Nov 05, 2007 at 01:44 UTC

    I think you are looking for a carriage return (without line feed):

    sub do_stuff { sleep 2; # for the sake of the example .. } $|=1; # turn off buffering, or you may never see what you write ... my @v = (1, 3, 10, 20); while (@v) { printf "\r%2d", shift @v; do_stuff(); }

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!

      Thanks. Yes, that was it. I had tried your suggestion earlier, but forgot the '\r'. It's working now.

      -- Burvil

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-25 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found