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.
In reply to (Ovid) Re: transliterating.. char-conversation
by Ovid
in thread transliterating.. char-conversation
by raptor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |