我正在尝试用来读取程序的用户输入,如下所示:
#!/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(或更多)值以类似的方式使用。 E.g
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>
答案 0 :(得分:1)
您可以输入以逗号或空格分隔的条件以保留格式
chomp(my $input = <STDIN>);
my ($condition1, $condition2) = split /[\s,]+/, $input;