|
发表于 2005-7-12 09:17:20
|
显示全部楼层
- print "===================================\n";
- print "y or n ?\n";
- $ch = getc(STDIN);
- print "you selected :", $ch, "\n";
- $ch = <STDIN>; # skip the last input line
- print "input a line: ";
- $str = <STDIN>;
- print "the first char is: ", chr(ord($str)), "\n";
- if (ord('y') == ord($str)) {
- print "yes\n";
- } else {
- print "no\n";
- }
- print "input: ";
- $data = "";
- read(STDIN, $data, 1);
- print "read: \[$data\]\n";
- if ('y' == $data) { print "yes\n"; }
- else {print "no\n";}
复制代码
===================================
y or n ?
y
you selected :y
input a line: yes
the first char is: y
yes
input: y
read: [y]
yes
这段代码必须要每次输入回车才能继续,如果想
实现单击一个键不需要回车,可参考perlfunc中
的getc的说明。 |
|