Reputation: 587
It is strange to me but in the below code neither I am getting any error nor result :(
use strict;
use warnings;
use File::Find;
my $path = $ARGV[0];
find({ wanted => \&GetappropriateFile }, $path);
my @all_file;
sub GetappropriateFile
{
my $file = $_;
#my @all_file;
# print "$file\n";
if ( -f and /traces[_d+]/)
{
print "$file\n";
# push(@all_file,$file);
open(FH, "<", $file) or die "cannot open file:$!\n";
while(my $line = <FH>){
print "$line\n";
$line =~ /Cmd line: com.android.phone/g;
#print "$line\n";
push(@all_file,$file);
last;
#print "$file\n";
}
close(FH);
}
}
Regx for below text files i have used ->/traces[_d+]/
traces_com.android.phone_01-22-2014_01-15-54 traces_01-22-2014_06-24-25 traces_com.skype.raider_01-22-2014_01-15-54 traces_com.android.mms_01-22-2014_01-15-54
Upvotes: 0
Views: 47
Reputation: 493
If the file ends with any kind of extension like .txt or .tbl. This code wont work because trace_[numbers].txt wont be found with the regx /traces[_d+]/. If you are working on windows it is posible you don't see the extension of the files. I recomend you to use the following pattern /traces[_d+].txt/ or something like that.
The other possibility is that the files you are trying to open are empty.
Upvotes: 1
Reputation: 5290
Your regular expression is matching files like:
traces_
tracesd
traces+
Is that what you wanted?
I'm guessing you meant:
/traces(_\d+)?/
to match:
traces
traces_1
traces_015
traces_8675309
...but I don't really know what you want.
Upvotes: 3