[英]How to print line by line of read c file after removing comments from it using perl
use Regexp::Common qw( comment );
local $/ = undef;
$_ = <DATA>;
s/$RE{comment}{C}//gs;
I have read complete file data and removed all comments from the read file. 我已读取完整的文件数据,并从读取的文件中删除了所有注释。 Now I want to print line by line instead of printing all data at once.
现在,我要逐行打印,而不是一次打印所有数据。
as per my understanding complete file data is in string $_
. 根据我的理解,完整的文件数据在字符串
$_
。 How to convert it into a array so that I can print it line by line. 如何将其转换为数组,以便可以逐行打印。
If the file data is in array I can do some string matching like that 如果文件数据在数组中,我可以像这样进行一些字符串匹配
Try: 尝试:
my @filecontents = split /\n/; # assuming the data is in $_
print "$_\n" foreach (@filecontents);
Hope that helps 希望能有所帮助
You can split your string at newline, and output the result list one by one. 您可以在换行符处分割字符串,然后一一输出结果列表。
foreach my $line (split /\n/) {
print "$line\n";
}
Or 要么
say for (split /\n/);
If your Perl supports say
. 如果您的Perl支持
say
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.