Re: transforming german characters

From: John W. Krahn (someone_at_example.com)
Date: 08/09/04


Date: Sun, 08 Aug 2004 23:41:42 GMT

steve_f wrote:
>
>>John W. Krahn wrote:
>>
>>Using a hash you could write that as:
>>
>>my %set1 = (
>> "\xDF" => 'ss',
>> );
>># Use a character class because all keys are single characters
>># If keys are multiple characters use alternation instead
>
> can you explain this a bit further? I'm not quite sure what you mean
> by alternation, but I really only looked up the escaped values for
> this particular problem.

Gunnar's example uses alternation.

>>my $key1 = '[' . join( '', keys %set1 ) . ']';

Changing this to use alternation would look something like:

my $key1 = '(?:' . join( '|', keys %set1 ) . ')';

> also here I start to get really lost....ok, you are loading into a scalar
> the keys as one long string...joining them with no space between...
> with two brackets so
>
> $key1 = [\xDF]
> $key2 = [\xC4\xD6\xDC\xE4\xF6\xFC]
> correct?

Yes.

> I see you use it down below in this substitution but it is a bit hard
> for me to understand:
>
> if ( $string =~ s/($key1)/$set1{$1}/og )
>
> well, if you have the time please give me a bit more clarrification
> on this because I haven't seen it before.

The substitution and match operators interpolate variables like double
quoted strings so after interpolation the substitution operator sees:

if ( $string =~ s/([\xDF])/ss/g )

John

-- 
use Perl;
program
fulfillment


Relevant Pages

  • Re: Complex Regular Expression
    ... > Here's what I have...I have a sequence of characters that need to be ... > create my regex pattern from that. ... This will backtrack after the failed attempt to match, ... Another way to get a full match is to modify the original alternation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: strange string match
    ... Since the order of characters and duplicate characters are ignored that could be simplified to. ... Although what you *really* want is to use alternation instead: ... 'Sat' *or* the string 'Sun'. ... current line is [SUCCESS]: all done! ...
    (perl.beginners)
  • Re: transforming german characters
    ... >Gunnar's example uses alternation. ... >> I see you use it down below in this substitution but it is a bit hard ... >The substitution and match operators interpolate variables like double ... ahhhhhhhhhh...all very fancy stuff, but I got it! ...
    (comp.lang.perl.misc)