in reply to Re: Scalar Vs. List context
in thread Scalar Vs. List context

This node was taken out by the NodeReaper on Jul 12, 2009 at 09:13 UTC

Replies are listed 'Best First'.
Re^3: Scalar Vs. List context
by AnomalousMonk (Archbishop) on Jul 12, 2009 at 05:36 UTC
    Just a couple of small (and slightly OT) points...

    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.)