食料品店の列をシミュレートするプログラムを作成しようとしています。a を入力すると、ユーザーは名前を追加できます。c が入力された場合、人が回線を離れることをシミュレートします。p を入力すると、名前のリストが出力されます。q を入力すると終了します。
私のコードは無限ループになってしまい、その理由がわかりません。値を入力しようとするたびに、無効な入力を読み取って終了しません。他のものが機能しているかどうかはわかりませんが、それは私が助けを必要としているものではありません.
$choice="";
$name;
@line=();
print "\n";
print "Choose an option:\n";
print "a: Add person to end of line\n";
print "c: Call the next person in line\n";
print "p: Print the list of people in line\n";
print "q: Quit\n";
print "\n";
while ($choice ne "q") {
print "Your choice:";
$choice = <>;
print "\n";
if($choice eq "a") {
print "Enter name:";
$name = <>;
push(@line,$name);
}
elsif ($choice eq "c") {
shift(@line);
}
elsif ($choice eq "p") {
for ($i=0;$i<=scalar(@line);$i++) {
print (@line[$i]);
}
}
elsif ($choice eq "q") {
exit;
}
else {
print "Invalid option";
}
}