sellwill has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I am pretty new to perl (and programming), I have a script that is pretty much exactly what I need--the only problem I have is that it only returns the first match +/-10 chars. How can I modify this to return ALL matches in a document instead of just the first?
my $string = 'string to search for'; open (TEXTFILE, 'searchfile.txt'); $_ = join('',<TEXTFILE>); close (TEXTFILE) while (/(.{0,10})$string(.{0,10})/gis) { print "Found: $1$string$2\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Return multiple matches in file
by ww (Archbishop) on Jun 14, 2011 at 00:35 UTC | |
|
Re: Return multiple matches in file
by davido (Cardinal) on Jun 13, 2011 at 23:11 UTC | |
by sellwill (Initiate) on Jun 13, 2011 at 23:58 UTC | |
by davido (Cardinal) on Jun 14, 2011 at 00:09 UTC | |
|
Re: Return multiple matches in file
by ww (Archbishop) on Jun 14, 2011 at 02:32 UTC | |
by Anonymous Monk on Jun 14, 2011 at 22:03 UTC | |
|
Re: Return multiple matches in file
by jethro (Monsignor) on Jun 14, 2011 at 01:07 UTC | |
|
Re: Return multiple matches in file
by planetscape (Chancellor) on Jun 15, 2011 at 06:34 UTC |