in reply to Difference between tr/// and s///?
From perlop, which you can access via the command perldoc perlop from the command line. (Try perldoc perldoc first)
tr/SEARCHLIST/REPLACEMENTLIST/cdsTransliterates all occurrences of the characters found in the search list with the corresponding character in the replacement list. It returns the number of characters replaced or deleted. If no string is specified via the =~ or !~ operator, the $_ string is transliterated. (The string specified with =~ must be a scalar variable, an array element, a hash element, or an assignment to one of those, i.e., an lvalue.) A character range may be specified with a hyphen, so "tr/A-J/0-9/" does the same replacement as "tr/ACEG-IBDFHJ/0246813579/". For sed devotees, "y" is provided as a synonym for "tr". If the SEARCHLIST is delimited by bracketing quotes, the REPLACEMENTLIST has its own pair of quotes, which may or may not be bracketing quotes, e.g., "tr[A-Z][a-z]" or "tr(+\-*/)/ABCD/". Note that "tr" does not do regular expression character classes such as "\d" or "[:lower:]". The <tr> operator is not equivalent to the tr(1) utility. If you want to map strings between lower/upper cases, see "lc" in perlfunc and "uc" in perlfunc, and in general consider using the "s" operator if you need regular expressions.s/PATTERN/REPLACEMENT/egimosx
Searches a string for a pattern, and if found, replaces that pattern with the replacement text and returns the number of substitutions made. Otherwise it returns false (specifically, the empty string). If no string is specified via the "=~" or "!~" operator, the $_ variable is searched and modified. (The string specified with "=~" must be scalar variable, an array element, a hash element, or an assignment to one of those, i.e., an lvalue.) If the delimiter chosen is a single quote, no interpolation is done on either the PATTERN or the REPLACEMENT. Otherwise, if the PATTERN contains a $ that looks like a variable rather than an end-of-string test, the variable will be interpolated into the pattern at run-time. If you want the pattern compiled only once the first time the variable is interpolated, use the "/o" option. If the pattern evaluates to the empty string, the last successfully executed regular expression is used instead. See perlre for further explanation on these. See perllocale for discussion of additional considerations that apply when "use locale" is in effect
--
Allolex
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Difference between tr// and s///?
by Abigail-II (Bishop) on Feb 06, 2004 at 11:30 UTC | |
by allolex (Curate) on Feb 06, 2004 at 13:40 UTC | |
by jacques (Priest) on Feb 06, 2004 at 16:36 UTC | |
by archangelq (Novice) on Feb 06, 2004 at 23:21 UTC | |
by allolex (Curate) on Feb 07, 2004 at 08:12 UTC |