从我在 Debian 上运行的脚本中读取用户输入时,我发现用户输入只有在按下 Ctrl-D 后才会终止,而不是在按下 Enter/Return 键之后。
my $userchoice = <>;
对于我的脚本,我要求用户输入文本并使用 Return/Enter 键终止它。什么可能导致我的脚本中出现这种情况?
在我的脚本中较早设置 slurp 模式是否与此有关?
我查看了 perdoc,但在那里找不到解释。
sub InteractiveMenu {
for my $key(0 .. $#desclist) {
my $value = $desclist[$key];
printf (" %-3s %-20s -> %-15s -> %-30s\n", $key, $desclist[$key], $iplist[$key], $filelist[$key] );
}
print "\nAvailable choices:\n";
printf " (R)oot key installation [installs your public key to remote servers]\n";
printf " (S)etup remote logging [sets up user account on remotes]\n\n";
print "Choose a server to work on:\n";
chomp(my $userchoice = <>);
}
sub ListRemotes {
print "Listing remote servers from $Confile\n";
open my $ReadHandle, "<", $Confile or die $!;
local $/; # enable localized slurp mode
chomp(my $content = <$ReadHandle>);
close $ReadHandle;
my @values = split('zone ', $content);
foreach my $val (@values) {
#print $val."\n-------------------------\n";
&ListWorker($val);
}
InteractiveMenu();
}