SaraBetsy has asked for the wisdom of the Perl Monks concerning the following question:
is this program going to replace my original document or will it just add info to the end of it? I have the doc named 'trynashort.txt' and I'm looking for the word 'tryna' in it and I think this code should grab the 25 characters before and after it. However, when I run it, I'm not seeing much evidence that it's working. Any thoughts on how to test it? Any answers would be helpful since I'm new to perl & coding. thank you.
my $string = quotemeta 'tryna'; my $slurp; { local $/ = undef; open my $textfile, '<', 'trynashort.txt' or die $!; $slurp = <$textfile>; close $textfile; } while( $slurp =~ m/ ( .{0,25} $string.{0,25} )gisx / ) { print "Found $1\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: question about finding strings?
by roboticus (Chancellor) on Nov 28, 2017 at 00:27 UTC | |
Re: question about finding strings?
by NetWallah (Canon) on Nov 28, 2017 at 05:10 UTC | |
Re: question about finding strings (regexes and slurping files)
by Discipulus (Canon) on Nov 28, 2017 at 08:21 UTC | |
by ww (Archbishop) on Nov 28, 2017 at 16:18 UTC | |
Re: question about finding strings?
by ww (Archbishop) on Nov 28, 2017 at 01:31 UTC | |
Re: question about finding strings?
by karlgoethebier (Abbot) on Nov 28, 2017 at 18:09 UTC | |
Re: question about finding strings?
by SaraBetsy (Initiate) on Dec 02, 2017 at 20:00 UTC |