我想問用戶多個問題。我有兩種類型的問題:Y/N或文件名輸入。我不知道如何將這一切都放在一個不錯的if
結構。我不確定我是否也應該使用'else'語句。有人能幫助我們嗎?這是我到目前爲止:向用戶提示多個問題(是/否和文件名輸入)
print "Do you want to import a list (Y/N)?"; # first question yes/no
my $input = <STDIN>;
chomp $input;
if ($input =~ m/^[Y]$/i){ #match Y or y
print "Give the name of the first list file:\n";
my $list1 = <STDIN>;
chomp $list1;
print "Do you want to import another gene list file (Y/N)?";
if ($input =~ m/^[Y]$/i){
print "Give the name of the second list file:\n" # can I use $input or do I need to define another variable?;
$list2 = <STDIN>;
chomp $list2;
print "Do you want to import another gene list file (Y/N)?";
}
}
爲什麼你在所有地方都用&&?它是我見過的最奇怪的東西。正常語句以分號結尾,而不是AND運算符。 – TLP
另外..你的問題是什麼?如何使用if-else? – TLP
@TLP我認爲&&是必要的,如果你想要在彼此之後做多件事情 – user1987607