Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How can I transliterate between languages?

by nardo (Friar)
on Jun 15, 2000 at 19:11 UTC ( #18299=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How can I transliterate between languages? - Answer contributed by nardo

I didn't quite understand what you meant when you were talking about vowels, can vowels not be mapped directly using the dny = #225 style? anyways, here is some code which might do what you want, but depending on what you want to do with the vowels, it might not be exactly what you want.

%letters = ('dny' => '#225', 'kh' => '#35', 'k' => '#12', 'h' => '#10', 'a' => '#8', 't' => '#7', 'o' => '#6', 's' => '#5'); $string = 'khatos'; #if you ever want to match more than 3 characters #then change the 3 below to whatever number #you want. while($string =~ s/([a-zA-Z]{1,3})/&roman($1)/e) {} print "$string\n"; sub roman { my $letter = shift; my $remainder; while(length($letter) > 0) { if(exists($letters{$letter})) { return $letters{$letter}.$remainder; } $remainder = chop($letter).$remainder; } #if the character isn't found in %letters it #will return '#?', if you return an alphabetic #character which isn't in %letters then the #program will loop forever. return '#?'; }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Corion]: :-D
[ww]: or a lot more than (22*2) for /me
[ww]: er -- senior cognitive deficiency: ((22+(22*2))

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-09-25 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (280 votes). Check out past polls.

    Notices?