Hi all,

thanks a lot for all the responses. Jeff's explanation of the snippet I mentioned in 
my original message did the trick. The hash-based solution is much faster now, 
although the first attempt (using multiple replacements on standard input) is still 
the fastest.

To answer John's questions:

>Your regular expressions look like they are longer then 8 bits.
>
>> >#!/usr/bin/perl -pw
>> >
>> >s/Ã??/{\\glqq}/g;
>> >s/Ã??/{\\grqq}/g;

This is due to mail encodings, they are really 8-bit characters.

>Do you want the fastest code?  The shortest code?  The most maintainable
>code?  What are you trying to accomplish?

Since I already had a reasonably fast and short solution, I wanted a more maintainable 
one, were I could easily extend the range of characters by editing the hash.

The hash solution is still a little sluggish, but it's more elegant, I think.

Jeff 'japhy' Pinyan wrote:

>Let me explain this for you, and fix it, too.
>
>  # this produces 'key1|key2|key3|...'
>  my $re = join '|',
>    map quotemeta($_),                  # this escapes non-alphanumberic
>                                        # characters;
>    sort { length($b) <=> length($a) }  # sorts by length, biggest first
>    keys %enctabelle;                   # the strings to encode
>
>What this does is put the keys in a string, separated by a | (which means
>"or" in a regex), quotemeta()d (which ensures any regex characters in them
>are properly escaped), and ordered by length (longest to shortest).  That
>last part is important:  if you have keys 'a' and 'ab', you want to try
>matching 'ab' BEFORE you try matching 'a', or else 'ab' will NEVER be
>matched.
>
I omitted the sort command since all patterns consist of a single (8-bit) character, 
so I guess your caveat is not applicable. My original message was garbled (see above).

Thanks again,

Jan
-- 
Hanlon's Razor: Never attribute to malice that which can be adequately explained by 
stupidity.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to