John W. Krahn wrote:
Brian wrote:
Hello
Hello,
I would like to do a recursive search of directories and files,
checking to see if a file contains a certain string.
<STDIN> will be a string containing whitespace(s).
As soon as I hit enter, I would like dummy.txt to be time stamped and
again at termination.
I'm playing about with 9.85GB (2.57 million files).
If possible, full pathnames of the files containing the string to go
to dummy.txt
I would like to see just how quickly PERL can complete a search, using
Windows search facility I killed the incomplete search after leaving
it to run for almost a day.
You could try this and see how it does:
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
open my $REPORT, '>', 'dummy.txt' or die "Cannot open 'dummy.txt' $!";
print $REPORT scalar localtime, "\n";
print STDERR 'Enter a string to search for: ';
chomp( my $string = <STDIN> );
find sub {
return unless -f;
open my $FH, '<:mmap', $_ or die "Cannot open '$_' $!";
local $/;
<$FH> =~ /\Q$string/ && print $REPORT "$File::Find::name\n" and return;
}, '/path/to/search/from';
print $REPORT scalar localtime, "\n";
__END__
John
Unknown PerlIO layer "mmap" at mysearch.pl line 14, <STDIN> line 1.
Cannot open file "dummy.txt No such file or directory at mysearch.pl
line 14 <STDIN> line 1.
the script is placed under C:
and I replaced '/path/to/search/from/' with '/test/'
(in "Windows-speak" test's pathname = C:\test )
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/