in reply to inserting program output in Tk::Text

To follow up a bit on the suggestion about just removing the useless output from the text:
# supposing the program output is all stored in $text: $text =~ s/.*\r//g;
Since "." won't match a "\n" (and Tk::Text does the right thing with "\n" in its display), the above regex will retain the original line count of the program output, and on each line, it removes everything up to and including the right-most "\r", leaving only the text that follows from that point to the next "\n" (which is all that would have been visible in a normal terminal display).

update: And as for actually making Tk::Text emulate a normal terminal display, you would need to keep track of the current line number in the text buffer (where the next chunk of program output will go), something like this:

# you need to know which line number you're at in the Tk::Text buffer # -- let's suppose that's in a variable called "$line_number" @updates = split( /\r/, $latest_output ); for my $string ( @updates ) { $tktext_widget->SetCursor( "$line_number.0" ); # go to start of +that line; $tktext_widget->deleteToEndofLine; $tktext_widget->Insert( $string ); $line_number += ( $string =~ tr/\n// ); }
That's a bit klugey because if one chunk of data from the program containins a lot of "\r"s, it does lots of changes to the widget's text content that won't be seen by the user. But it ought to work as intended, I think. (another update: fixed typo on "+=")