zhihua li wrote: > hi netters, Hello,
> I'm curious if there's any smart code to calculate the "distance" > between the matches in a text. > Suppose I have a text like this: > syhk...yes...uhg;ka=...yes...yiealg.....yes.......ghe;a...yes... > Apparently it has multiple words of "yes". I'd like to know how many > characters there are between the first and the last "yes". $ perl -le' my $string = q/syhk...yes...uhg;ka=...yes...yiealg.....yes.......ghe;a...yes.../; my $lookup = q/yes/; my $last = rindex $string, $lookup; my $first = index $string, $lookup; print $last - ( $first + length $lookup ) if $last >= 0 && $first >= 0; ' 48 John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>