perl写的一个命令行交互的脚本,按q键退出,否则显示用户输入。
#!/usr/local/bin/perl5
use strict;
use warnings;
sub test {
while (1) {
# display the prompt
print "sditest> ";
# Get input form STDIN, this is short for my $get = <STDIN>
chomp (my $get = <>);
# Quit when user pressed 'q', otherwise print what ever input
if ($get eq 'q') { # How to determine user pressed Esc here?
exit;
}
else {
print $get, "n";
}
}
}
test();