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

Hello Monks,

I'm trying to make myself a small code testing program where i can type in multiline code at the command line and execute it. So far this is fine but i would like to be able to edit the previously executed code at the command line and then re-execute it. I suppose i need to supply the previously typed in code to STDIN somehow but i don't even know if this is possible.

Any ideas will be greatfully received.

Oh...this is all on Win32, thanks.

TeraMarv.

Replies are listed 'Best First'.
Re: Edit STDIN
by ambs (Pilgrim) on Mar 30, 2005 at 08:03 UTC
    I think you need some terminal-aware modules like Term::Readline.

    Alberto Simões

Re: Edit STDIN
by graff (Chancellor) on Mar 30, 2005 at 08:05 UTC
    Perhaps if you showed us an example of the code you're typing at the command line, we'd have a better idea of what you're trying to do. Without that, the question is too vague to get any useful feedback.

    Are you talking about being able to re-execute a previous command with the ability to edit a recalled command line before running it again? Some versions of the "MS-DOS Prompt" shell support this (more or less), but if you get a Win32 port of the unix "bash" shell, you'll find that its command-line history/editing features are much better (along with a lot of other features being much better as well).

Re: Edit STDIN
by starbolin (Hermit) on Mar 31, 2005 at 05:58 UTC

    I know that probably the last thing you want is another thing to learn but, this is the kind of thing a good programmer's editor can do for you.

    Alternately you can type your code into your whatever editor you have. Then <cut> your code into the scratchpad. After running: "perl -d" <Paste> your code into the debugger. Typing "c" will execute your code.

    After using your editor to make changes to your code, type "R" and paste your new code.

    If you insist on writing something yourself I would highly recommend copying heavily from something like Text::LineEditor


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}