1

我正在尝试使用以下方式读取程序的用户输入:

#!/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>
4

1 回答 1

1

您可以输入以逗号或空格分隔的条件以保留格式,

chomp(my $input = <STDIN>);

my ($condition1, $condition2) = split /[\s,]+/, $input;
于 2013-08-28T15:20:59.790 回答