Hi,
Yet another newbie question about regular expressions:
I'd like to find and replace bits of text as usual. However, rather than replace all occurrences in one quick swoop using the s-operator and the g-flag, the replacement is so complex that it cannot be expressed as a straight substitution. So I would have to find a piece of text, process it in a separate function, and replace the matched text with the newly computed text. This goes on for n interesting matches in the input.

Can I do this kind of thing in a simple loop, processing all matches one by one? My understanding is that pos and some special variables will tel me the character index of the mach in a string. But if I then go and modify the string using substr to do the substitution, wil it reset the search position to the beginning when trying to match the next interesting bit? The replacement text is by nature longer than the original so the input string needs to grow on each substitution which might present a problem to the matching operator. I took a look at perlop and some books I have on Perl but didn't end up with a definitive answer of how I should solve this problem.

That was the problem abstractly put, here's the specific instance:
I'm writing a program to convert notes given in the music macro language to their equivalent pitches that are applied using markup tags for speech synthesizers. I can match a note easily, and have functions for computing the pitch and the tag in question. As the note values don't depend on each other in any way, I'd like to completely process one note at a time, doing the replacement, and then continue matching the next note where it previously left off. Naturally there are other tokens than just notes in the input so I need to maintain the position of the note data in the input string. If I modify a separate copy of the string, it will throw off the pos() indeces because the substitutions will change the length of the copy.

Any help appreciated as usual.

PS: If the problem statement is still a bit fuzzy or incomplete, just ask and I'll try to provide more info.

--
With kind regards Veli-Pekka Tätilä ([EMAIL PROTECTED])
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to