Re: fastest way to substitute

2002-07-29 Thread Paul Tremblay
On Sat, Jul 27, 2002 at 02:40:52PM -0700, John W. Krahn wrote: > > s[([&<>]|(?<=\\)$rx)][$rep{$1}]go; > John, this doesn't work. My representative line is: \ldblquote \rdblquote & < > \par My code is: my %rep = qw( & & > >

Re: fastest way to substitute

2002-07-28 Thread Janek Schleicher
Paul Tremblay wrote at Sun, 28 Jul 2002 03:38:56 +0200: > I don't understand this syntax: > > >> s[([&<>]|(?<=\\)$rx)][$rep{$1}]go; > ^^^ > > Is that another way of telling the regex that you don't want to save the value? It a zero-width positive look-behind assertion. It says

Re: fastest way to substitute

2002-07-27 Thread Paul Tremblay
On Sat, Jul 27, 2002 at 02:40:52PM -0700, John W. Krahn wrote: > > I thought '<' and '/>' were already in the hash values? If so, wouldn't > this work? > > s[([&<>]|(?<=\\)$rx)][$rep{$1}]go; > > > I don't understand this syntax: > s[([&<>]|(?<=\\)$rx)][$rep{$1}]go; ^^^

Re: fastest way to substitute

2002-07-27 Thread Jeff 'japhy' Pinyan
On Jul 27, John W. Krahn said: >> No, $1 is either "&" or undef. Perhaps you want: >> >> s[([&<>])|\\($rx)][<$rep{$+}/>]go; >> >> That $+ means "the last () that matched". But that still replaces & with >> <&/>. So you'd need to make the '<' and '/>' part of the %rep hash's >> values. I wou

Re: fastest way to substitute

2002-07-27 Thread John W. Krahn
Jeff 'Japhy' Pinyan wrote: > > On Jul 27, Paul Tremblay said: > > >The only problem is how I should replace "&", ">", and "<". I think I'll > >do single line subs for this text. Even with huge files it shouldn't > >take more than 1/2 a second or so, and that allows me to use your > >original met

Re: fastest way to substitute

2002-07-27 Thread Jeff 'japhy' Pinyan
On Jul 27, Paul Tremblay said: >The only problem is how I should replace "&", ">", and "<". I think I'll >do single line subs for this text. Even with huge files it shouldn't >take more than 1/2 a second or so, and that allows me to use your >original method to speed things up. > >Or this just oc

Re: fastest way to substitute

2002-07-27 Thread Paul Tremblay
On Sat, Jul 27, 2002 at 11:23:59AM -0400, Jeff 'japhy' Pinyan wrote: > > That's because my method requires creating a hash each time. If you were > to take that out of the function, it would run faster. Right. This makes perfect sense. I followed your advice and put the hash outside of the su

Re: fastest way to substitute

2002-07-27 Thread Jeff 'japhy' Pinyan
On Jul 27, Paul Tremblay said: >I ran a benchmark on your method, and it actually proved slower. I ran a >test line 10,000 times. Directly substituting each line took 38 wall >seconds. Using your method took 60. That's because my method requires creating a hash each time. If you were to take th

Re: fastest way to substitute

2002-07-26 Thread Paul Tremblay
On Fri, Jul 26, 2002 at 02:02:54PM -0400, Jeff 'japhy' Pinyan wrote: Jeff: I ran a benchmark on your method, and it actually proved slower. I ran a test line 10,000 times. Directly substituting each line took 38 wall seconds. Using your method took 60. I included my test below, in case I made

Re: fastest way to substitute

2002-07-26 Thread Jeff 'japhy' Pinyan
On Jul 26, Paul Tremblay said: >Is there a quicker way to substitute an item in a line than reading the >line in each time? > >I am writing a script to convert RTF to XML. One part of the script >involves simple substitution, like this: > >s/\\ldblquote //g; >s/\\rdblquote //g; >s/\\emdash //g; >

Re: fastest way to substitute

2002-07-26 Thread Janek Schleicher
Paul Tremblay wrote at Fri, 26 Jul 2002 19:55:46 +0200: > Is there a quicker way to substitute an item in a line than reading the line in each >time? > > I am writing a script to convert RTF to XML. One part of the script involves simple >substitution, > like this: > > s/\\ldblquote //g; > s/

Re: fastest way to substitute

2002-07-26 Thread Paul Tremblay
On Fri, Jul 26, 2002 at 02:02:54PM -0400, Jeff 'japhy' Pinyan wrote: > > It's best to come up with a hash of strings and replacements: > > my %rep = qw( > ldblquote rt_quote > rdblquote lt_quote > emdashem_dash > rquoter_quote > tab tab > lquote