On Aug 13, ERIC Lawson - x52010 said: >Given that "1 while ..." logic works for my needs here, though, is there a >reason I should use the sexeger logic instead? Is the "1 while ..." >expression more costly? It seems, on the face of it, that the "1 >while" is more readily decypherable by another programmer unfamiliar with >my coding style. You have to beware of telescoping substitutions (done via the 1 while s///g construct) that are recursive. Here's an example: %trans = ( 'man' => 'good man', 'good' => 'nice' ); $re = join '|', map quotemeta, keys %trans; $text = "you're a good man"; 1 while $text =~ s/\b($re)\b/$trans{$1}/g; The first time around, that produces "you're a nice good man". On the second time, it produces "you're a nice nice good man". And so on. That's just a general caveat of the 1 while s///g approach. >That perception, of the relative opacity of the sexeger, may be mistaken, >of course, and is at best a subjective judgement, so I wouldn't attach >much weight to it, given any substantial reason favoring the sexeger >expression as compared to the "1 while" expression. Um, you might not want to use the sexeger approach if you're not comfortable with it. Or you might want to comment it, and let other readers (like yourself) know what you're doing. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how does "1 while $scalar =~ s/(%A .*)\n%A /$1\;/g;" work?
Jeff 'japhy/Marillion' Pinyan Mon, 13 Aug 2001 10:41:28 -0700
- how does "1 while $scalar =~ s/(%A .*)\... ERIC Lawson - x52010
- Re: how does "1 while $scalar =~ s... Jeff 'japhy/Marillion' Pinyan
- Re: how does "1 while $scalar =~ s... Jeff 'japhy/Marillion' Pinyan
- Re: how does "1 while $scalar =~ s... ERIC Lawson - x52010
- Jeff 'japhy/Marillion' Pinyan