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

I recently installed a script I found on "out there." Its installation prompted me for a number of inputs to ensure that it set itself up properly.

I found, though, that I had to enter every value correctly and could not make any mistakes. (The script did not respond to Delete ot Backspace.)

My questions are:

  1. Is this the standard behavior of reading data through STDIN?

  2. Is there a way to prompt for user input in a more user-friendly fashion, e.g. so that mistakes and typos can be corrected?

Apologies if this is a FAQ. I looked, but was not able to find it.

Replies are listed 'Best First'.
Re: Keyboard entry question...
by rlk (Pilgrim) on Oct 12, 2000 at 20:47 UTC
    In general, no, this is not standard behavior. I say "in general" becuase this is really a system dependent issue. When perl reads from the standard input, it's not actually looking at what you type on the keyboard, it's asking the operating system to tell it what you're typing. (Yes, I'm oversimplifying a great deal here. The specifics depend on what OS you're running, though.) This way, you can, with a command line like (on DOS or Linux, respectively)
    C:\ perl myscript.pl < inputfile bash$ myscript.pl < inputfile
    Then perl gets the contents of inputfile fed to it as it's standard input.

    Anyway, I see 3 possible causes for your problem.

    1. You're using some bizarre OS that doesn't recognize backspace properly. I'd imagine this is unlikely, as most people who use bizarre OSes tend to know about that sort of quirk (and claim that it's a feature ;)
    2. You're running the script on a shell account on a remote computer, and your telnet program is sending the wrong character as a backspace. Again, even if you are telneting, this is unlikely, as you'd have problems backspacing on everything, not just this script.
    3. The most likely cause is that, for whatever reason, the script either isn't using standard input, or has used Term::ReadKey to put the input into "raw" mode.

    The answer to question 2, then, is don't worry about it. Just use STDIN, and all should be fine. If you're really concerned, run this and see if backspace works:

    #!/usr/bin/perl -w while (<>) { print "You typed: $_\n"; }

    --
    Ryan Koppenhaver, Aspiring Perl Hacker
    "I ask for so little. Just fear me, love me, do as I say and I will be your slave."

(tye)Re: Keyboard entry question...
by tye (Sage) on Oct 12, 2000 at 20:37 UTC

    Either this program is going out of its way to disable (or change) backspace/delete or you have backspace/delete improperly configured and you just don't usually notice because your shell is going out of its way to deal with that.

    The better way to read from <STDIN> is Term::ReadLine and friends. They allow you to edit what you type instead of just backspace/delete.

    You might want to check "man stty" if you are on a Unix system.

            - tye (but my friends call me "Tye")