On 6/29/2004 9:58 PM, David Arnold wrote:

All,

Suppose I have a number of lines in a latex file like this:

\backans{If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute
        to find a solution.}

I'd like to scan the file and replace all of these with this format:

\begin{answer}
If $x=y^{2n}$ and $z=y^{3n}_{11}$, then we can substitute
to find a solution.
\end{answer}

I'm looking for suggestions as to how to make this change with my perl
script. I am puzzled by the use of nested braces and how I can be sure I've
got everything between the opening and closing brace.

You may want to take a look at Text::Balanced or Regexp::Common (the Regexp::Common::balanced subclass).


For this type of work though, I generally prefer the more straightforward method of walking thru the file one char at a time, counting opening braces and substracting closing braces until the count reaches zero. At that point you can take the appropriate action. For this task, I really don't believe regexs offer any advantage and are probably slower (I'm sure Japhy will correct me if I'm wrong here).

Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to