#!/usr/bin/perl -w use strict; # # This creates a list of ten strings, with index 0 corresponding to # "zero", etc. # my @numbers = qw(zero one two three four five six seven eight nine); # # Note that we can combine the chomp statement with reading from STDIN # in this way: # print "Enter a string containing a number: "; chomp(my $answer = ); # # Using split with the empty string splits between each character # my @characters = split "", $answer; # # Loop through each character... # foreach my $char (@characters) { # # Note: Modifying $char changes the element in @characters # automatically! # $char = $numbers[$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";