#!/usr/bin/perl -w use strict; # # Note: the international characters in the French and German numbers # may not appear properly on your screen, but Perl should be able to # run this. If you have difficulty change "zéro" to "zero" and "fünf" # to "fuenf". # my %numbers = (ENGLISH => [qw(zero one two three four five six seven eight nine)], SPANISH => [qw(cero uno dos tres cuatro cinco seis siete ocho nueve)], FRENCH => [qw(zéro un deux trois quatre cinq six sept huit neuf)], GERMAN => [qw(null eine zwei drei vier fünf sechs sieben acht neun)], JAPANESE => [qw(zero ichi ni san yon go roku nana hachi kyu)], ); # # Take the first element out of @ARGV and use that as the language. # Check that the language is one we know how to translate. # my $language = uc shift; die "Unknown language \"$language\"\n" unless exists $numbers{$language}; # Here we are operating on @ARGV instead of STDIN, so we first make a # string containing all the words in @ARGV and then split that into an # array of individual characters. # my @characters = split "", "@ARGV"; # # Loop through each character, modifying the elements of @characters # if it is a digit. # foreach my $char (@characters) { $char = $numbers{$language}[$char] if ($char ge "0" && $char le "9"); } # # Using an array inside a double-quoted string causes a space to be # inserted between each element # print "The output is: @characters\n";