http://www.perlmonks.org?node_id=64008


in reply to (tye)Re: Counting number of characters in a string
in thread Counting number of characters in a string

I just realized that most strings won't have most characters in them so this can be sped up significantly via:

my $count= 0; for( keys %{ { map {$_,1} unpack "C*", $str } } ){ my $c= pack "C", $_; $count += () = $str =~ /\Q$c\E/g; }
        - tye (but my friends call me "Tye")