Reputation: 3304
I am trying to fetch the list of .cpp files that have a class "MyClass" being used in it.
Here is the snippet:
use File::Find::Rule;
my @match_files = File::Find::Rule->file()->name('*.cpp')->in('.')->grep("MyClass");
However, this is giving the following error:
Can't call method "grep" without a package or object reference at ./script.pl line 20.
Can someone help me understand what is wrong with this call?
Upvotes: 0
Views: 273
Reputation: 57600
The error tells you that the LHS of the last ->
operator was not an object. That is because the in
method evaluates the rule and returns a list of matching files.
So you should probably swap the grep
and the in
:
my @files = File::Find::Rule->file->name('*.cpp')->grep(qr/MyClass/)->in('.');
You can re-read the documentation at MetaCPAN.
Upvotes: 3