in reply to Phonetic Translation

I'd use split to break it into characters, and a hash to map characters to their names.
my %trans = ( 1 => "one", 2 => "two", ... z => "zulu", ); foreach (split //, $line) { if (exists $trans{$_}) { print $trans{$_}, " "; } else { print $_, " "; } }
Update: Fixed missing ; in hash assignment

Replies are listed 'Best First'.
Re: Re: Phonetic Translation
by ellem (Hermit) on Aug 27, 2003 at 21:01 UTC
    Oh, I have used split a zillion times and because I didn't have a character (like , ) to split on I didn't realize I could use it. (No I don't know what I am doing.)

    I am sure everyone knows, but in case there is someone who does not there needs to be semi-colon after the hash for the code to compile:
    my %trans = ( 1 => "one", 2 => "two", ... z => "zulu", ) ; #<---note semi-colon foreach (split //, $line) { ....
    Oh and to deal with the case thing I did this:
    print "Enter some letters and numbers: " ; my $line = <STDIN> ; chomp $line ; $print = lc $line ; ... foreach (split //, $print) { ...

    --
    ellem@optonline.net
    There's more than one way to do it, but only some of them actually work.