我正在尝试编写一个读取管道数据的perl脚本,然后根据该数据提示用户输入.prompt_for_action我正在尝试执行以下脚本:
#!/usr/bin/perl
my @hosts = ();
while (<>) {
my $host = $_;
$host =~ s/\n//; # strip newlines
push(@hosts, $host);
}
for my $host (@hosts) {
print "Do you want to do x with $host ? y/n: ";
chomp(my $answer = <>);
print "You said `$answer`.\n";
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,没有等待用户输入,它只是吹过而没有等待我输入:
$ echo "test1.example.com
> test2.example.com" | ./prompt_for_action
Do you want to do x with test1.example.com ? y/n: You said ``.
Do you want to do x with test2.example.com ? …Run Code Online (Sandbox Code Playgroud)