[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Substitution



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In a script a coworker of mine is writing, it is necessary to do the
following:

Substituting a substring ($pat) inside of a big (>500K) string
($text), but the first time it is changed to one thing ($s1) and
afterwards it is changed to another thing ($s2). Also, $s1 contains
the original $pat (in fact, it is $pat . $s2). So far, the best we've
been able to come with is:

$text =3D~ s/$pat/$s1/;
1 while ($text =3D~ s/$pat(.*?)$pat/$pat$1$s2/);

but obviously it is horribly inefficient.

Does someone know of a better/faster way? Is there any one-liner for
that?

                                                       /L/e/k/t/u


P.S.: I hope this is not against the spirit of Fun With Perl. I know
how implement it with index, etc., but it is very puzzling not being
able to find a regexp way to do that...

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQA/AwUBN20q/v4C0a0jUw5YEQLqiQCg+dgSz9dPR5pDWTqCL9+1f1L1mF4AoL0I
LKmhe9t4LdHRyg9i0NSP5X51
=3D4qsv
-----END PGP SIGNATURE-----


=3D=3D=3D=3D Want to unsubscribe from this list? (Don't you love us anymore=
?)
=3D=3D=3D=3D Well, if you insist... Send mail with body "unsubscribe" to
=3D=3D=3D=3D fwp-request@technofile.org