gpt4 book ai didi

windows - 为什么我不能终止这个 while 循环?

转载 作者:可可西里 更新时间:2023-11-01 10:54:45 26 4
gpt4 key购买 nike

我编写了以下脚本:

print "Will accept input until EOF";  

while(defined($line = <STDIN>)){
print "Input was $line \n";
if(chomp(@line) eq "end"){
print "aha\n";
last;
}
}

我有两个问题:

  1. 为什么当我在控制台中键入 end 时,我看不到循环中的 ahabreak (last 等于 break 对吧)?
  2. 停止 while 循环的 EOF 组合键是什么?我以为它是 Windows 中的 ctrl+D 但它不起作用。

最佳答案

你的脚本没有使用use strict;使用警告;。否则,您会注意到 $line 不是 @line

此外,chomp 不会返回更改后的字符串,它会原地更改并返回删除的字符数。

在 MSwin 中,Ctrl+ZEnter 用作 EOF。

更新:修复了 EOF。

关于windows - 为什么我不能终止这个 while 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15865844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com