Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking for a string in a file and trying to print if found. It's late and I'm sure I'm missing something. Is obviously not working. Here's the script and file
#!/usr/bin/perl my $string = quotemeta 'title'; my $slurp; { local $/ = undef; open my $textfile, '<', 'test2.txt' or die $!; $slurp = <$textfile>; close $textfile; } while( $slurp =~ m/ ( .{0,25} $string.{0,25} )gisx / ) { print "Hi"; print "Found $1\n"; } #/ \Q$wanted\E /x;
text file contains
test test test title test test test test
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: looking for string in file and trying to print
by poj (Abbot) on Jan 31, 2016 at 08:45 UTC |