Brian wrote:

John W. Krahn wrote:

Brian wrote:

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. :-(

Let me be more explicit.  Replace:

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

With:

find sub {
    return unless -f;
    open my $FH, '<', $_ or die "Cannot open '$_' $!";
    while ( <$FH> ) {
        /\Q$string/ && print $REPORT "$File::Find::name\n" and return;
        }
    }, '/path/to/search/from';



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

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


Reply via email to