如何在 Windows 上使用 Perl 从 STDIN 读取单个字符? [英] How do I read a single character from STDIN using Perl on Windows?
问题描述
使用 Perl,我如何从 STDIN
捕获单个字符而不需要用户按 Enter(类似于 C 的 getch()
函数)?
Using Perl, how do I capture a single character from STDIN
without needing the user to hit enter (similar to C's getch()
function)?
Perl 有一个 getc()
函数,但是根据 perlfunc:
Perl has a getc()
function, but according to the perlfunc:
但是不能单独使用它来获取单个字符无需等待用户按回车键.
However, it cannot be used by itself to fetch single characters without waiting for the user to hit enter.
perlfunc 文档 do 提供了一种使用 getc()
读取单个字符的方法,但它需要使用 stty
操作终端设置.我正在编写的脚本需要在 Windows 上运行(没有 cygwin、msys 等) - 所以这不是一个选项.
The perlfunc docs do provides a way to read a single character using getc()
but it requires manipulating the terminal settings using stty
. The script I'm writing needs to work on Windows (without cygwin, msys, etc.) - so that's not an option.
推荐答案
你想要这个模块:Term::ReadKey.
这篇关于如何在 Windows 上使用 Perl 从 STDIN 读取单个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!