gpt4 book ai didi

Perl 输出覆盖自身

转载 作者:行者123 更新时间:2023-12-03 03:09:22 24 4
gpt4 key购买 nike

我有代码循环遍历文件中的行,并尝试打印出每一行,并在开头和结尾添加一些内容。

但是,我得到这样的输出:“nominalte milks”。

基本上,行(标称)后面的位会覆盖行的开头。我知道删除 chomp 和 regex 行可以阻止这种效果,但我需要它在没有空格的一行上。我哪里出错了?

while ($line = <INPUT>) {

chomp $line;
$line =~ s/ //g;
printf "\@attribute %s nominal\n", $line;
}

最佳答案

您的输入文件可能来自 MS Windows,行尾编码为 CR-LF。您也可以仅 s/\r// 删除 CR。

关于Perl 输出覆盖自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8082182/

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