gpt4 book ai didi

linux - 使用系统写入 sh 终端后防止 Perl 程序打印换行符

转载 作者:太空狗 更新时间:2023-10-29 11:41:18 24 4
gpt4 key购买 nike

我正在尝试从文件中提取数据到 Perl 程序,并使用“foreach”循环在 Linux sh 终端中执行它,但每次 Perl 将值返回到 sh 终端时,它都会在打印下一个字符串之前打印一个新行,这会导致我的脚本失败。我该如何防止这种情况发生?

open(FILE, "input") or die("Unable to open file");

# read file into an array
@data = <FILE>;

# close file
close(FILE);

foreach my $x(@data) {
system "/granite_api.pl -type update_backdoor -project tgplp -test_id $x -turninid 4206";
}

预期输出:

/granite_api.pl -type update_backdoor -project tgplp -test_id example -turninid 4206

实际输出:

/granite_api.pl -type update_backdoor -project tgplp -test_id example 
-turninid 4206

最佳答案

@data = <FILE>;

@data 包含输入文件中的所有行。每行以 LF 结尾。您需要从每个 $x 中删除它,例如使用 chomp(删除 $/ 中设置的尾随字符)

foreach my $x ( @data ) {
chomp $x;
system "/granite_api.pl -type update_backdoor -project tgplp -test_id $x -turninid 4206";
}

参见 chomp in perldoc

关于linux - 使用系统写入 sh 终端后防止 Perl 程序打印换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47748050/

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