in reply to Reaped: Re^2: Scalar Vs. List context
in thread Scalar Vs. List context
The transliteration operator tr or y (see tr/SEARCHLIST/REPLACEMENTLIST/cds in perlop) does not support character classes, so the expression
$t_count=($text=~ y/[tT]/t/);
will substitute any of the characters ] [ T t in $text with a t character and return the total count of characters so transliterated to $t_count.
>perl -wMstrict -le "my $s = 'ab]cd[efthiTj'; my $count = $s =~ tr/[Tt]/t/; print $s; print $count; " abtcdtefthitj 4
Also, the characters | . (vertical bar, period) have no special meaning in a regex character class, so in the regex
@a = m/([\d|\.]+)\D+/g;
the class [\d|\.] is "the class of any decimal digit, vertical bar or period character". (Although escaping | or . in a class will do no harm.)
|
|---|