lenp has asked for the wisdom of the Perl Monks concerning the following question:

I've written a small program, and I want to be able to edit a line of text that I have previously entered. It sounds so simple, yet I have been unable to find anything that will help me do it.

e.g.
$Line = <STDIN>; #Now edit this line $Line = EditThisLine($Line); #This function should display the line +and allow me to edit it.
The closest I've got to a solution is here (using Term::ReadLine): http://osdir.com/ml/perl-beginners/2009-03/msg00453.html

This looks like the answer, except it doesn't work for me. Maybe because I'm running my program in a cmd.exe window on desktop running Vista. (Could that really have anything to do with it)?

If anyone can point me in the right direction, I would appreciate it so much.

Thank you …. Len

Replies are listed 'Best First'.
Re: Edit a line of text
by Anonymous Monk on Nov 07, 2010 at 16:14 UTC
    readline reads a line, up to and including the newline

    once you hit enter, the cursor moves to the next line, you can't go back.

    so the solution is to read characters instead, and trap the newline

    You may need to use Term::ReadKey or Win32::Console to accomplish this

    Then you can print "\r", EditThisLine ... but be sure to pad the string so its at least as long it was before (add spaces on end)

    You'll eventually have to advance the cursor yourself print "\n";