
effc
Novice
Dec 6, 2012, 5:09 AM
Post #1 of 2
(2334 views)
|
Search for string and print to output file
|
Can't Post
|
|
I am attempting to write a perl script to search every file in a directory for a string. Unfortunately when I run it my output file is empty, but I know there are some in there! Help use strict; use warnings; my $string = 'Reproductive exam'; #string that I am looking for my $file = $_; open my $results, '>', 'results.txt' or die "Unable to open results file: $!"; #this works sub printFile { return unless -f and /\.sift$/; open my $fh, '<', , $_ or do { warn qq(Unable to open "$File::Find::name" for reading: $!); return; }; if (/\Q$string/) { print $results "$File::Find::name\n"; return; } }
|