in reply to Counting using transliteration


You should do something like this:     $Acount = $line =~ tr/A/A/; However, if you want to count the number of every character on a line you could do something like this:

    $chars{$_}++ for split //, $line;

Or if you want to filter out a range of characters later:     $chars[ord $_]++ for split //, $line; Set the scope of %chars or @chars as appropriate.

--
John.

Replies are listed 'Best First'.
Re: Re: Counting using transliteration
by demerphq (Chancellor) on Feb 25, 2002 at 12:05 UTC
    Or moderately more efficiently
    $chars[$_]++ for unpack "c*",$line; $chars{$_}++ for unpack "c*",$line;
    Or course unpack returns the ordinal value not the characater..

    Yves / DeMerphq
    --
    When to use Prototypes?