我正在尝试使用以下方式读取程序的用户输入:
#!/usr/bin/perl -w
use strict;
if ($#ARGV == 0) {
print "What condition are you sorting?\t";
chomp(my $condition = <STDIN>);
# Use $condition in further blocks of code...
}
这是有效的。但是,当我不知道如何输入 2 个(或更多)值以类似方式使用时。例如
if ($#ARGV == 1) {
print "What conditions are you comparing?\t";
chomp(my $condition1 = <STDIN>);
chomp(my $condition2 = <STDIN>);
允许我输入两次,但格式失真:
What conditions are you comparing? <condition1>
<condition2>