Using print to overwrite a line

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Using print to overwrite a line

    Is there a simple way to print over an existing line?

    For example: I would like to have a progress report that reads 10%, 20%
    etc. I don't want to print a new line each time. I want to write over
    the existing line and have it update as it goes.

    --Paul

    Paul Harwood Guest

  2. Similar Questions and Discussions

    1. To print a document from command line
      I want to invoke the print dialog of acrobat from command line. I can easily do this using '/p' argument in Windows. But how to do this on a MAC??
    2. In-line graphics won't print
      Greetings, I'm using a small graphic as the bullet for a bulleted list. The bullets display properly within FreeHand. However, if I print it (or...
    3. Windows Print PDF from Command Line
      Franke, I have a problem some thing like this one. I need to have my user be able to print using adobe printer. I tried the above and it does only on...
    4. 'print' output on one line
      I have a perl program ( with DBI ) which prints out a line to STDOUT after every 100 database commits. I would like the 'print' to just refresh...
    5. printer in jetdirect only print one line...
      I use /opt/hpnpl/bin/addqueue command to create a printer queue in Solaris, but when I issue lp -d printer1 eagle , I only get one line printed...
  3. #2

    Default RE: Using print to overwrite a line

    Paul Harwood wrote:
    > Is there a simple way to print over an existing line?
    >
    > For example: I would like to have a progress report that
    > reads 10%, 20%
    > etc. I don't want to print a new line each time. I want to write over
    > the existing line and have it update as it goes.
    >
    > --Paul
    Use "\r" to move to the beginning of the current line (depending on the
    capabilities of your terminal). Also unbuffer STDOUT. Something like this:

    $| = 1;
    for (1 .. 5) {
    print "\rStep $_";
    sleep 1;
    }
    print "\rFinished.\n";

    Bob Showalter Guest

  4. #3

    Default Re: Using print to overwrite a line

    Paul Harwood wrote:
    >
    > Is there a simple way to print over an existing line?
    >
    > For example: I would like to have a progress report that reads 10%, 20%
    > etc. I don't want to print a new line each time. I want to write over
    > the existing line and have it update as it goes.
    Hi Paul.

    I presume you're writing to a file? Can you show us an example of what
    you mean? It's probably best if you rewrite the file, but that's not
    a problem.

    Rob


    Rob Dixon Guest

  5. #4

    Default Re: Using print to overwrite a line

    This is not the most elegant solution, but it did only take me five minutes.
    The salient part is the backspace and printing blanks bit. A more elegent
    solution would figure out how to destructively clear the line using something
    from ncurses.

    #!/usr/bin/perl -w

    $|=1;

    @reports = ("starting", "now we're cooking", "Almost half!", "Over the hump",
    "Almost done!", "Finito!");
    #print @reports;

    foreach $item (@reports)
    {
    print $item;

    sleep 1;
    print "\b" x length($item);
    print ' ' x length($item);
    print "\b" x length($item);

    }

    --
    Music so wishes to be heard that it calls on some to give it voice and some to
    give it ears.
    [url]http://www.hacksaw.org[/url] -- [url]http://www.privatecircus.com[/url] -- KB1FVD


    Hacksaw Guest

  6. #5

    Default Re: Using print to overwrite a line

    This doesn't work if the line being printed is longer than the width of the terminal.
    Flimm Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139