Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Recursive substitution

by grizzley (Chaplain)
on Nov 10, 2009 at 08:34 UTC ( #806153=note: print w/replies, xml ) Need Help??


in reply to Recursive substitution

Is it possible to perform a s///g substitution in such a way that the substituted text is itself recursively parsed?

I don't find any use for it. The way I always think of regexes is

s/find some text/react to this text/somehow;

If you find text, the 'react' part has enough information to build any replace string you want. There you can use another regex (nested) to do something (and I can provide examples if you want). And this can be useful.

But the approach:

s/find some text, replace it, find more text in replaced string/react to second finding/

? Not good: first part of s/// is to find something, second is to replace. For analysing text not for changing it.

Replies are listed 'Best First'.
Re^2: Recursive substitution
by JadeNB (Chaplain) on Nov 10, 2009 at 15:37 UTC

    While I agree that your approach to s/// is the most common, and probably the best, if we wanted there to be only one way to do things then we'd be using Python the principle that TIMTOWTDI can surely be extended to TIMTORTDI (there is more than one reason to do it!). :-)

    As an illustration of the use of recursive substitution, consider macro-expansion languages. Recursion means the difference between a language that is Turing complete and one that is not. (Note that the latter article is quoted approvingly—sometimes totality is better than Turing completeness.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://806153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2020-10-01 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (174 votes). Check out past polls.

    Notices?