The simple way is to not print a newline after each piece. Then, before each new piece, print as many backspaces as you need ("\b") to get you back to the start of where the new data will go. The new data will have to be at least as long as the old, so pad anything shorter with spaces. Do this with standard output unbuffered. Here's a simple sub I wrote to print ongoing totals:

use strict; use FileHandle; use vars qw(@ISA @EXPORT $VERSION); use Exporter; $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw(print_total); sub print_total($$) { my $total = shift; my $label = shift; my $n; if ($total == 1) { STDOUT->autoflush; print $label; } $n = length($total); print "$total"; while ($n-- > 0) { print "\b"; } }

The other fun one is to print sequences of | / - \ to get one of those spinning progress indicators.


In reply to Re: printing in a specific area of the console by steves
in thread printing in a specific area of the console by io

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.