erase line on stdout with perl

S

Sherm Pendley

Is there any way to erase a line in perl, so that i can rewrite over that
line?

A carriage return "\r" will return the cursor to the beginning of the
line, without advancing to the next line. It doesn't erase the current
line, but you can do that by printing a line of spaces.

For more detailed control, have a look at Curses.pm.

sherm--
 
B

Bob Walton

lucas said:
Is there any way to erase a line in perl, so that i can rewrite over that
line?

Hmmmm...well, there is seek(), which will work if the output is an
ordinary file and you know how long the line was. You are doing this on
STDOUT, I gather from your subject, and your mileage might vary
depending on what STDOUT is hooked up to and your OS. If STDOUT is
hooked up to a console, seek() might not do what you want (it doesn't on
my system, Windoze 98SE w/AS build 806). A given console may respond to
various control characters and escape sequences which might permit a
line to be erased. Question: Why not just don't output it in the first
place? Or use a sub or an object which delays the output by one line,
with an option to not output the pending line when called?
 
L

lucas

Thanks for the quick posts. The \r might work nicely, so I'll give it a
try. And the terminal size will be usful as well. The reason I need to
write to stdout immediatly, and not delay it is because this is a chat
client, and the user needs to see what they are typing. I just thought it
would be nice if certain circumstances exist.

Thanks again,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,371
Latest member
Brkaa

Latest Threads

Top