本文介绍了无法在文件中搜索字符串并在另一文件中输出该行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Perl的新手,并且已经写了代码在文件中一行的开头搜索"PERFORM"一词,并且相应的行应打印在另一个文件中.我还需要将PERFORM之后的字符串存储在数组中
Hi,
I am a newbie to Perl and have written a code to search for the word "PERFORM" at the start of a line in a file and the corresponding line should be printed in another file. Also I need to store the string after PERFORM in an array
use strict;
se warnings;
open FILE1, "<Test3.txt" or die "Cannot open File1.txt!";
open FILE2, ">File2.txt" or die "Cannot open File2.txt!";
while (my $string=<FILE1>) {
if($string =~ m/^PERFORM\s*/)
{
print (FILE2 "$string\n");
}
}
close FILE2;
close FILE1;
但是我也得到以"*"和"END-PERFORM"开头的行的输出.
预先感谢.
But I get output of lines starting with "*" and "END-PERFORM" also.
Thanks in advance.
推荐答案
但是我也得到以"*"和"END-PERFORM"开头的行的输出.
预先感谢.
But I get output of lines starting with "*" and "END-PERFORM" also.
Thanks in advance.
这篇关于无法在文件中搜索字符串并在另一文件中输出该行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!