我正在学习 Perl 并且已经查看了这个问题,但是尽管它没有错误地终止,但无法让它为我工作。
我输入了一个它应该想要的文件(name-0-0-0
),但它只是while
完全跳过了循环。
open FILE, '+>>userinfo.txt';
print("What is your name?");
$name = <>;
chomp $name;
while (<FILE>) {
chomp;
($nameRead,$wins, $losses, $cats) = split("-");
if ($nameRead eq $name){
print("Oh hello $name, your current record is $wins wins - $losses losses - $cats ties");
print("Would you like to play again? type y for yes or n for no\n");
$bool = <>;
if ($bool == "y"){
print("Okay let's play!");
play();
exit();
}
else {
printf("well fine goodbye!");
exit();
}
}
}
好吧,看来我的问题确实与+>>有关。我正在尝试添加到文件中,但我希望能够写入,而不仅仅是追加。我将其更改为 +< 并且一切正常。谢谢你们,我真的很感激!