Staralfur has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use File::Find; my $dir = '/home/me/Desktop/tasks/Korpora/'; my $string = 'Alice '; open my $results, '>', '/home/me/Desktop/results.txt' or die "Unable to open results file: $!"; find(\&printFile, $dir); sub printFile { return unless -f and /\.html$/; open my $fh, '<',, $_ or do { warn qq(Unable to open "$File::Find::name" for reading: $!); return; }; while (<$fh>) { if (/\Q$string/) { print $results "$File::Find::name\n"; return; } } }
Dear Monks, I have a big directory with html articles, where I would like to search for several strings at the same time. For example for: Alice, Tom, Jamie, party, something. How can I do it with the module file find? I have already tried to search for $string1 and $string2 and also $string1&&string2, but it doesn't work. I am a newbie and haven't worked with file find before, but it seems to be the easiest way. Can you help me? Thanks in advance!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File::Find find several strings in one directory
by stevieb (Canon) on May 09, 2017 at 17:24 UTC | |
by Staralfur (Novice) on May 09, 2017 at 18:06 UTC | |
Re: File::Find find several strings in one directory
by FreeBeerReekingMonk (Deacon) on May 09, 2017 at 19:02 UTC | |
by Staralfur (Novice) on May 10, 2017 at 08:29 UTC | |
Re: File::Find find several strings in one directory
by thanos1983 (Parson) on May 10, 2017 at 11:26 UTC | |
Re: File::Find find several strings in one directory
by karlgoethebier (Abbot) on May 10, 2017 at 17:58 UTC |
Back to
Seekers of Perl Wisdom