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

Re: [FWP] Q on Substitution improvement



Randal L. Schwartz writes:
|    $map{'"'} = """;
|    $map{"\n"} = "<br>";
|    ...
|    my $pat = "(" . join("|", map quotemeta $_, reverse sort keys %map), ")";
|    eval q{$pat = qr/$pat/} if $] >= 5.005;
|    s/$pat/$map{$1}/g;

Maybe it's way too early in the morning, but why "reverse sort keys %map"
and not just "keys %map"?

Also, does the qr/$pat/ do anything useful in this case? s/// would have to
do it anyway, and being there's only one substitution, it seems it would
still happen only once without the eval. If there were multiple s/// with
$pat as the expression to match I can see a distinct advantage, but not here.

But then, it's really early...
Brian

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org