Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have one string and its substring and would like to find which is the position of the words that match the substing. For instance, for the string:
this is a test
and the substing
is a test
I want to have as output the
2 3 4
Here is my code but is returs me the number of the first charachter.
my $str = "this is a test";</p> my $sub = "is a test"; if ($str =~ /\b$sub\b/) { print "match at char ",@-[0], "\n"; }
Any help would be useful.
Tahnks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find the position of substring
by hdb (Monsignor) on Apr 22, 2015 at 11:59 UTC | |
by Anonymous Monk on Apr 22, 2015 at 12:28 UTC | |
|
Re: Find the position of substring
by Laurent_R (Canon) on Apr 22, 2015 at 17:59 UTC |