in reply to Re: Replacing with null
in thread Replacing with null
He wants to replace the second Fate| substring, whereas your solution replaces the rightmost Fate| substring.
If there are only two Fate| substrings in the string, it is equivalent; but if there are more than two, then your solution is wrong.
Thus your solution is actually not more general, but rather more restrictive since it pre-supposes that there will only be two Fate substrings in the string!
But do not be disappointed, we are all here to learn and using index was a good idea. Have a look at the following small change to your program:
See what it does? I starts looking for $search after the first occurrence of $search.my $match_pos = index $str, $search, (index $str, $search) + length $s +earch;
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|