in reply to How do you clear the current line?

print "^[[K";
(that's "ESC[K") will clear from the current curson position until end of line.
Update: Yes, tye, directly cut and pasting the above will not work (hence the added description of "that's 'ESC[K'") (it was embedded as an ESCAPE using my text editor). To get an ESCAPE in Perl, you'll need to use "\e".

Replies are listed 'Best First'.
(tye)Re: How do you clear the current line?
by tye (Sage) on May 14, 2001 at 22:32 UTC
    print "^[[K"; gives me: ^[[K perhaps you meant:
    print "\c[[K"; # or print "\e[K";
    but be aware that those will only work for ANSI-ish terminals (which are pretty common, though).

            - tye (but my friends call me "Tye")
Re: Re: How do you clear the current line?
by Nicodemus (Initiate) on May 15, 2001 at 01:46 UTC
    That's exactly what I'm looking for. I guess that explains all the weird ^[[D type output when pressing the cursor keys without anything tied to stdin.

    I have a couple questions though... how compatible is this escape sequence? I am targeting as many POSIX compatible machines as possible. I would use Term::Cap, but I know that many systems are phasing out termcap completely, including Debian GNU/Linux and AIX. Obviously it would be better to find out the exact character that the term expects based on it's TERM type, but termcap is the only mechanism I know for doing as such.

    Also, is there a full list of all the possible escape characters like this one?

    Thanks,
    Nicodemus

      That's a fairly basic ANSI sequence: existing long before Termcap or Termlib (way back to pre-1980 machines).

      I used this for the lookup of the sequence you were looking for. Normally, I just consult a very old Z80A programming manual I have lying around someplace.