in reply to transliterating.. char-conversation

Without looking at your code too closely, I see some areas for improvement. As a good rule of thumb, don't alternate on single characters. By adding strict (and switching the alternation to character classes for a performance boost), I got your script to work:

use strict; my $tstr = 'abc äÄöÖüÜß test'; my %subsTable = ( 'ä' => 'ae', 'Ä' => 'AE', 'ö' => 'oe', 'Ö' => 'OE', 'ü' => 'ue', 'Ü' => 'UE', 'ß' => 'ss' ); my $notInSQL = qr{['`´",%\$]}; my $inSQL = qr{[`´",\$]}; sub blah { my $str = shift; my $regex = join "", map { quotemeta $_ } keys %subsTable; $regex = "[$regex]"; print "Regex: $regex\n"; $str =~ s/($regex)/$subsTable{$1}/g; return $str }; print "orig : $tstr\n"; print blah($tstr)."\n";

When I added strict, I immediately discovered that you had referred to %subsTable as %subsHash in your subroutine. By switching the variable name, it worked fine.

Cheers,
Ovid

Vote for paco!

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: transliterating.. char-conversation
by raptor (Sexton) on Aug 08, 2001 at 00:48 UTC
    thanx ...
    i'm doing this in write-and-run script and later all will be me moved in module where I'm always using 'strit' of course :").. but see it is needed even in write-and-run scripts
    thanx for char-classes I forgot about them :")