0
这是我的脚本,用于检查文件中是否存在版权。使用grep的Perl多行模式匹配
use strict;
use warnings;
use List::Util 'first';
my $filename="sample.txt"; # this file name will be passed-in to the script.
my @fileContent=`cat $filename`;
my $copyrightFound = first { /copyright .* Shakespeare/i } @fileContent;
if (!$copyrightFound) {
print "\nERROR: Copyright missing\n";
exit;
}
#copyright Found
print @fileContent;
if (grep /Copyright (c) \d+ by Bill Shakespeare\nAll rights reserved./,@fileContent) {
print "\nCopyright is good\n";
} else {
print "\nCopyright needs to be fixed\n";
}
打印:
$ perl copyrightCheck.pl
Copyright (c) 2010 by Bill Shakespeare
All rights reserved.
Copyright needs to be fixed
但版权是好的,有没有更好的办法来检查呢?或者我的grep命令有什么问题?也可以在同一行或下一行出现All rights reserved.
,我可以用\n*
查看一样吗?