Windows Perl line editor with editable default value?

command-line, perl, stdin, stdout, windows

Solution

ExtUtils::MakeMaker has a `prompt` function, which is very platform independent. I'm not suggesting that it be used in your case, but the POD for IO::Prompt::Tiny states that its `prompt` function is based on the way `ExtUtils::MakeMaker` does it. The smoke tests seem to reflect that IO::Prompt::Tiny has achieved better portability (including Windows). You might give it a try.

It's a little early in the smoke testing of this new module to say for certain, but if it's based on `ExtUtils::MakeMaker`'s `prompt`, it's designed for portability.

Term::Prompt is another option. It has been around longer and has a longer history of multi-platform smoke test success. But it has non-core dependencies of `Term::ReadKey` and `Text::Wrap`. `IO::Prompt::Tiny` sticks to core dependencies, if that's a concern.

use IO::Prompt::Tiny qw( prompt );
my $input = prompt( 'Proceed? (y/n)', 'n' );

Output:

Proceed? (y/n) [n]

Problem

I'm running Strawberry Perl on Windows and I want to print a "Default Value" into the command prompt, so that a user can edit it, then press Enter and Perl will see it as a new STDIN line. I've been told to use IO::Prompt, but it has been established that this does not work in Windows. Short of making a GUI with Tk or something, how can I do this?

Original source

Related problems