Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Phonetic Translation

by benn (Priest)
on Aug 27, 2003 at 18:13 UTC ( #287121=note: print w/ replies, xml ) Need Help??


in reply to Phonetic Translation

Further to Paladin's fine answer, I'd just add a couple of points...

You'll probably want to lc either $line or each split character, unless you want to distinguish between upper and lower, in which case (forgive the pun) you'll need something like 'a'=>alpha, 'A'=>ALPHA in your lookup hash.

Whitespace may also be confusing to the user - certain rendering systems (HTML for instance) ignore multiple spaces, so you may want to add something like ' '=>'space'.

Cheers, Ben.


Comment on Re: Phonetic Translation
Select or Download Code
Re: Re: Phonetic Translation
by tcf22 (Priest) on Aug 27, 2003 at 20:07 UTC
    If the case matters, you could use this
    my %trans = ( a => "alpha", b => "beta", ... z => "zulu" ); my $line = 'AbZaBz'; foreach (split //, $line) { if (exists $trans{lc($_)}) { print (($_ ne lc($_)) ? uc($trans{lc($_)}) : $trans{$_}); } else { print $_; } print ' '; } __OUTPUT__ ALPHA beta ZULU alpha BETA zulu

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://287121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2015-07-03 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls