Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: recursive &func breaks s/(foo)/&func($1)/eg Message-ID: <1991Mar13.185951.15222@jpl-devvax.jpl.nasa.gov> Date: 13 Mar 91 18:59:51 GMT References: <5128@atexnet.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 24 In article <5128@atexnet.UUCP> lawrence@epps.kodak.com (Scott Lawrence) writes: : I think that I have discovered a problem with substitution and : recursion. Please someone demonstrate that I am wrong. You're right, but you'll be wrong when 4.0 comes out. :-) When you do a pattern match, the regular expression routines sometimes save a copy of the input string so that $1, $&, etc. work right after the pattern match. The substitution operator was depending on this string to stay there so that it could continue the substitution using the value of $', more or less. Unfortunately, the recursion clobbered that temporary value. The do_subst() routine just needed to make sure it could restore $' after evaluating the right-hand side, and I figured out a way to do that by manipulating the pointers, so I don't have to actually copy the contents of $' around. Note, however that order of evaluation will still be important. If you say s/(whatever)/&recurse($1) . $1/eg; The first $1 refers to the $1 from this substitution, while the second $1 refers to the $1 from pattern match done within &recurse. (I think.) Larry