Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As I said earlier, there is some directory called verilog which is HDL language used for hardware description. Inside this directory there are many sub-directories and .v files are available. So I need to search for a pattern called clk in all the files and the directory with the line number exactly where is the pattern located in each file and i need the count how many times clk has appeared. Now i could able to go through the directories and files but I could not get the line number of the file where the pattern has occured and the count(how many times the pattern has repeated) this is what I am looking for.Can you Plz help me on this?

#!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);

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);
print "The pattern is found in $file_ and number of lines is $count \n";
share|improve this question

If your script is trying to use File::Find, please change FILE to File. Perl is case sensitive.

BTW, posting a commentary to the error message would also be nice, not mentioning a question.

Update: After seeing your code, I can identify some problems: you probably define $count and $match at a wrong scope (hard to tell, because you never use $match). I tried to fix the issue:

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;
    print "The pattern is found in $file_ and number of lines is $count \n" if $match;
share|improve this answer
Can't locate File/ in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.12.4 /usr/local/share/perl/5.12.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.12 /usr/share/perl/5.12 /usr/local/lib/site_perl .) at line 8. BEGIN failed--compilation aborted at line 8.still same error. – prashanth Nov 7 '12 at 13:35
@prashanth: No, it is a different error. This time, Perl cannot find File::Slurp, which is not a CORE module. How did you install it? – choroba Nov 7 '12 at 13:43
Now I am not able to remove both the errors I did this/ sudo cpan followed by install::slurp – prashanth Nov 7 '12 at 18:07
Was the installation successful? Does File/ exist in any of the directories listed in @INC? Also, install::slurp is an invalid command, please try to show the exact commands and messages, otherwise there is no way anyone can help you. – choroba Nov 7 '12 at 22:14
Ya installation was successful. Now there is no error as the previous now it is only saying syntax errors in File::find. I did Install::Slurp it installed all dependencies. – prashanth Nov 8 '12 at 6:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.