You attempt to clear the entire screen / tty / window / whatever just to overwrite a single line? I don't think that this is what the OP *really* wanted.

And by the way, your code is not portable: Not all non-Win32 platforms implement a clear command that clears the screen.

Assuming that STDOUT or STDERR write to a screen / tty / window is also wrong. Another user may run the program with STDOUT redirected to /dev/null to get rid of the anoying progress messages (think of a Makefile), and the program randomly cleans the screen, often including the entire scrollback buffer. All output from other programs running before is lost. In cron jobs or other non-interactive environments, you usually don't want progress messages, but just results or errors reported back. Imagine a cron job that tells you in 10.000 lines that it has just processed 0.01% of the job, 0.02% of the job, 0.03% of the job, 0.04% of the job, 0.05% of the job, ..... 99.99% of the job, 100.00% of the job.

Progress indicators can be useful. But you don't want them unconditionally. I would prefer a command line switch to enable or disable them, and a reasonable default, i.e. no progress indicator when STDOUT and/or STDERR aren't ttys (-t STDOUT / -t STDERR).

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: how to erase screen output? by afoken
in thread how to erase screen output? by llancet

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.