continous update (print)

Discussion in 'Perl Misc' started by Lars Madsen, Jul 31, 2006.

  1. Lars Madsen

    Lars Madsen Guest

    if one e.g . wants to write a countdown one can do this as

    $|=1;
    ....
    # some loop
    printf "% 4d\r", $count;

    where \r then makes sure that we reprint on them same line over and over again.

    But what if you want to do this with several lines at once?

    I have a data structure with, say, 10 special entries that changes every second,
    I would like to have a continous overview if these numbers in the same fashion
    as above.

    How would one do that?


    --

    /daleif (remove RTFSIGNATURE from email address)
     
    Lars Madsen, Jul 31, 2006
    #1
    1. Advertising

  2. Lars Madsen

    Lars Madsen Guest


    > A simple solution is to clear the screen before printing:
    >
    > my $clear = qx(clear);
    >
    > while ( 1 ){
    > print $clear;
    > printf "%s\n",'some text';
    > }
    >


    well yes, besides the fact that the screen flickers a bit, clearing the screen
    seems to work.


    --

    /daleif (remove RTFSIGNATURE from email address)
     
    Lars Madsen, Jul 31, 2006
    #2
    1. Advertising

  3. Lars Madsen

    -berlin.de Guest

    Aukjan van Belkum <> wrote in comp.lang.perl.misc:
    > Lars Madsen wrote:
    > >
    > >> A simple solution is to clear the screen before printing:
    > >>
    > >> my $clear = qx(clear);
    > >>
    > >> while ( 1 ){
    > >> print $clear;
    > >> printf "%s\n",'some text';
    > >> }
    > >>

    > >
    > > well yes, besides the fact that the screen flickers a bit, clearing the
    > > screen seems to work.
    > >
    > >

    > Yes it does ... i didn't say it was pretty ... just simple ;-)


    Put a delay in the loop and update the screen only once per second or so.
    The flicker will get much bettter.

    Anno
     
    -berlin.de, Jul 31, 2006
    #3
  4. Lars Madsen

    Lars Madsen Guest

    es it does ... i didn't say it was pretty ... just simple ;-)
    >
    >
    > Put a delay in the loop and update the screen only once per second or so.
    > The flicker will get much bettter.
    >
    > Anno


    I already do that, it looks ok.


    --

    /daleif (remove RTFSIGNATURE from email address)
     
    Lars Madsen, Jul 31, 2006
    #4
  5. Lars Madsen wrote:
    > if one e.g . wants to write a countdown one can do this as
    >
    > $|=1;
    > ...
    > # some loop
    > printf "% 4d\r", $count;
    >
    > where \r then makes sure that we reprint on them same line over and
    > over again.
    > But what if you want to do this with several lines at once?
    >
    > I have a data structure with, say, 10 special entries that changes
    > every second, I would like to have a continous overview if these
    > numbers in the same fashion as above.
    >
    > How would one do that?


    Use the Curses module to position the cursor before each output block.

    jue
     
    Jürgen Exner, Aug 1, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    19
    Views:
    10,382
    Neredbojias
    Jun 29, 2005
  2. mobil
    Replies:
    3
    Views:
    261
    Basilisk96
    May 1, 2007
  3. keto
    Replies:
    0
    Views:
    1,043
  4. nirvana
    Replies:
    4
    Views:
    322
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    399
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page