On 10/25/2012 05:24 PM, Andy Bach wrote:
On Thu, Oct 25, 2012 at 3:57 PM, Weidner, Ron <rweid...@idexcorp.com> wrote:
In the following regex what is the "t" character doing?
$linebuf =~ tr/\n/:/;
tr/// is the "translate", er, transliteration operator. Same as
"y///" - from/like a unix util ("tr"). Takes any of the left hand
side ("\n" here) and turns them into the right hand side (":");
Returns the count of transliterations. Much like s/// subst though it
doesn't interpolate variables (though it does, obviously, allow
metachars) - see perldoc perlop for all the details
please don't say tr is much like s///. they are very different operators
and they only share the =~ (bind) op. tr is character oriented and it
isn't 'any' of the left side. each char in the left side is translated
to the char on the right side in the same index slot. s/// is regex and
string oriented and the whole right side is the replacement string.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/