无法在@INC 中找到 FILE/Find.pm

无法在@INC 中找到 FILE/Find.pm

正如我之前所说,有一个目录叫做 verilog,它是用于硬件描述的 HDL 语言。这个目录中有许多子目录,并且有 .v 文件可用。所以我需要在所有文件和目录中搜索一个名为 clk 的模式,并给出行号,以便确定该模式在每个文件中的确切位置,并且我需要计算 clk 出现的次数。现在我可以浏览目录和文件,但我无法获得出现该模式的文件的行号和计数(该模式重复了多少次),这就是我要找的。你能帮我吗?

#!usr/bin/perl -w
#use strict;
#use FindBin;
#use lib File::Spec->catdir($FindBin::Bin,'Lib');
#use ExtUtils::Installed;

use File::Find;
use File::Slurp;
my $in_dir="/home/prodigydell3/verilog";
my @all_files;
my $pattern='test>clk(\n|\t|\s)</test';

find(sub {
push @all_files,$File::Find::name if(-f $File::Find::name);
},$in_dir);


my $count=0;
foreach my $file_(@all_files){

my @file_con=read_file($file_);
foreach my $con(@file_con){

my $match = "true" if ($con=~m/$pattern/igs);
$count++;
}
print "The pattern is found in $file_ and number of lines is $count \n";
}

答案1

如果你的脚本试图使用文件::查找,请更改FILEFile。Perl 区分大小写。

顺便说一句,对错误信息发表评论也很好,而不是提及问题。

更新:看到您的代码后,我发现了一些问题:您可能在错误的范围内定义了 $count 和 $match(很难说,因为您从未使用过 $match)。我尝试修复此问题:

#!/usr/bin/perl
use warnings;
use strict;

use File::Find;
use File::Slurp;
my $in_dir = '/home/prodigydell3/verilog';
my @all_files;
my $pattern = 'test>clk(\n|\t|\s)</test';

find(sub {
         push @all_files, $File::Find::name if (-f $File::Find::name);
     }, $in_dir);


foreach my $file_ (@all_files) {

    my $count = 0;
    my $match;
    my @file_con = read_file($file_);
    foreach my $con (@file_con) {

        $match = 1 if $con =~ m/$pattern/igs;
        $count++;
    }
    print "The pattern is found in $file_ and number of lines is $count \n" if $match;
}

相关内容