hi, you probably want to use s/// instead of tr///.
# perl -wle '$_="yyyy"; s/yyyy/(\\d\\d\\d\\d)/; print' (\d\d\d\d) have a look at perldoc perlop to see what tr or y really does: tr/SEARCHLIST/REPLACEMENTLIST/cds y/SEARCHLIST/REPLACEMENTLIST/cds Transliterates 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/ACEGIBDFHJ/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/". HTH! Martin On 22:20:53 01/01/2008 [EMAIL PROTECTED] wrote: > Hi there, > > I'm quite new to perl, and now having problem with using parentheses > in translation strings. For example, I want to replace the 4 digit > year code 'yyyy' with '(\d\d\d\d)', so it can be used for grouping in > string matching later. I expected the code would be like: > > $org_str =~ tr/yyyy/\(\d\d\d\d\)/; > > Then the result is '(((('. It seems the parens were not escaped > properly, shouldn't the backslash escape the round brackets? If I > remove the backslashes before brackets, the result is the same. If I > use double backslashes, that is, \\(\d\d\d\d\\), the result is '\\\\'. > Can someone inform the right way to do this? Many thanks in > advance! :-) > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/