Introducing UNIX and Linux |
PerlOverview |
Single character translationWe start by considering character-by-character translation. You
will recall the use of the shell command
The string which appears between the first two slashes is called
the search string, and the string between the last two
slashes is the replace string. For example, the following
command lowercases each letter in $word =~ tr/A-Z/a-z/; The following command replaces each vowel in $word =~ tr/AEIOUaeiou/@/; The option $word =~ tr/AEIOUaeiou//d; Worked exampleWrite a Perl script to copy standard input to standard output
with all digits deleted and the symbol while (<STDIN>) { $_ =~ tr/@0-9/#/d; print $_; } |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck