John W. Krahn wrote:
Brian wrote:
John W. Krahn wrote:
Brian wrote:

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__

Unknown PerlIO layer "mmap" at mysearch.pl line 14, <STDIN> line 1.

I thought that Windows supported memory mapping, oh well.

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/'

There is no string '/path/to/search/from/' in the example I posted, there is however the string '/path/to/search/from'.

Well spotted :-)

If all the files are small enough to fit into memory you could change '<:mmap' to '<:raw'.

If the files and search string are "standard" text files then you could replace:

They are all tiny text files.

I now have the following code:-

#!/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, '<', $_ or die "Cannot open '$_' $!";
    while ( <$FH> ) {
        /\Q$string/ && print $REPORT "$File::Find::name\n" and return;
        }, '/test';

print $REPORT scalar localtime, "\n";


I'm getting syntax error line 17 and line 19, it is also complaining about missing right curly braces.
I can't see the problem. :-(
Brian

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to