对于Science课程中的一个项目,我正在用Perl制作游戏。这是我的游戏介绍,
# Solar Game
# Copyright (c)2013 Donovan Roudabush
# Protected by GPU
print " _________ .__ ________ \n";
print " / _____/ ____ | | _____ _______ / _____/_____ _____ ____ \n";
print " \_____ \ / _ \| | \__ \\_ __ \ / \ ___\__ \ / \_/ __ \ \n";
print " / ( <_> ) |__/ __ \| | \/ \ \_\ \/ __ \| Y Y \ ___/ \n";
print "/_______ /\____/|____(____ /__| \______ (____ /__|_| /\___ > \n";
print " \/ \/ \/ \/ \/ \/ \n";
print "Version 1.0 Beta\n\n";
print "Developed by Donovan Roudabush\n";
print "https://github.com/sharksfan98/solargame\n\n";
print "Press enter to start\n";
$ok = <STDIN>;
chomp $ok;
print "Enter the number of players\n";
$num = <STDIN>;
chomp $num;
现在,使用值 $ num (存储玩家数量),如何打印下面的行(x)数量的玩家来收集他们的名字?
print "Please enter your name\n";
$name1 = <STDIN>; # Name1 can also be Name 2 or Name3 for second or third player
chomp $name1;
答案 0 :(得分:2)
Use a loop您可以将名称存储在数组中:
my @names;
for (1 .. $num) {
print "Please enter your name\n";
my $name = <STDIN>;
chomp $name;
push @names, $name;
}