On Jan 1, 2008 1:20 PM, <[EMAIL PROTECTED]> wrote: > 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.
Wait -- What are you replacing with what? Usually, when someone uses yyyy in the context of a "4 digit year", they mean the four digits of the year number itself, like 2008 or 1620. (Of course, the people who "usually" do this are far from both the year 999 and the year 10000.) Do you mean to say that you're actually replacing the letter 'y' four times in a row? And what are you replacing it with? In Perl, \d is most commonly used to mean an element of a regular expression. Do you mean an actual literal backslash character followed by a letter 'd'? Or do you mean the letter 'd' itself? You say you're doing this "for grouping in string matching later". What does that mean? Are you really doing something like this? s/(\d\d\d\d)/yyyy/; # replace four digits with yyyy > I expected the code would be like: > > $org_str =~ tr/yyyy/\(\d\d\d\d\)/; The tr/// operator doesn't work like that. It's primarily for changing single characters for other characters, not substrings for substrings. You may be thinking of s///, but I'm not sure what you're really doing. s/yyyy/(dddd)/g; # replace every yyyy with (dddd) Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/