Saurav Bhasin
Saurav Bhasin

Reputation: 13

Can't call method "_compile" error when using File::Find::Rule

Can't call method "_compile" without a package or object reference at /homes/sauravb/perl5/lib/perl5/File/Find/Rule.pm line 292

#!/usr/bin/perl
use strict;
use warnings;
#use File Perl Module
#use Cwd sub perl module
use File::Find::Rule;
use Cwd;
use Cwd 'chdir';

chdir "/volume/regressions/results/JUNOS/HEAD/EABUPDTREGRESSIONS/15.1/15.1F5";

my $cwd = getcwd();

my $fh;
sub fileindex {
        open($fh, ">", "/homes/sauravb/line_with_X-TESTCASE.txt" ) || die $!;

        my $rule =  File::Find::Rule->new;

        my @files = $rule->any (File::Find::Rule->name('*.log'),
                                File::Find::Rule->in($cwd)
        );


        #print $fh map{ "$_\n" } @files;

}


fileindex();

Upvotes: 0

Views: 98

Answers (1)

ikegami
ikegami

Reputation: 385754

any allows you to specify alternate sets of criteria. For example, the following returns all files whose name ends with .log or .txt.

my @files =
   File::Find::Rule
   ->any(
      File::Find::Rule->name('*.log'),
      File::Find::Rule->name('*.txt'),
   )
   ->in($dir_qfn);

Instead, you passed one criteria plus the names of all the files in a directory to any. That is incorrect.

Did you simply want the list of log files in the directory? If so, you simply need

my @files =
   File::Find::Rule
   ->name('*.log')
   ->in($dir_qfn);

Or if you want to make sure they're plain files (and not directories),

my @files =
   File::Find::Rule
   ->name('*.log')
   ->file
   ->in($dir_qfn);

Upvotes: 4

Related Questions