Martin Barth <[EMAIL PROTECTED]> suggested:

> On Mon, 21 May 2007 08:41:13 +0200
> Andreas Moroder <[EMAIL PROTECTED]> wrote:
> 
> > Hello,
> > 
> > in our application I have to convert all german
> > Umlaute in a string to 
> > a two char combination ä to ae, Ö to OE and so on.
> > 
> > Can anyone please tell me how to do this ?

> for example:
> 
> % echo "äpfel klöster übelkeit" | perl -ple 's/ä/ae/; 
> s/ü/ue/; s/ö/oe/;'
> aepfel kloester uebelkeit

I would suggest you use a hash to map your conversions:

#!/usr/bin/perl -w

use strict;

my %map = ( 'ä' => 'ae', 'Ä' => 'Ae',
                'ö' => 'oe', 'Ö' => 'Oe',
                'ü' => 'ue', 'Ü' => 'Ue',
                'ß' => 'ss' ); # add needed conversions!

my $test = "Äpfel Klöster Übelkeit";

my $in =  '[' . join( '', keys %map ) . ']';

$test =~ s/($in)/$map{$1}/eg;

print "$test\n";

HTH,
Thomas

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


Reply via email to