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*
を使用して同じことを確認できますか?