question about speed of sequential string replacement vs regex or

John Bokma john at castleamber.com
Wed Sep 28 16:14:51 EDT 2011


Willem <willem at toad.stack.nl> writes:

> Eli the Bearded wrote:
> ) In comp.lang.perl.misc, Willem  <willem at toad.stack.nl> wrote:
> )> In Perl, it would be applicable.  You see, in Perl, you can call a function
> )> in the replacement of the regex substitution, which can then look up the
> )> html entity and return the wanted unicode literal.
> )
> ) A function? I'd use a hash.
>
> A function can return a sensible value for unknown substitutions.

You can do that also in the RHS of the substitution and still keep it
readable if you use something like

s{..}{

    your
    code
    goes
    here
}ge;

However, a function can be easier on the eye:

s{...}{ some_good_name( ... ) }ge;

-- 
John Bokma                                                               j3b

Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html



More information about the Python-list mailing list