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:
- tye (but my friends call me "Tye")my $count= 0; for( keys %{ { map {$_,1} unpack "C*", $str } } ){ my $c= pack "C", $_; $count += () = $str =~ /\Q$c\E/g; }
|
---|
In Section
Seekers of Perl Wisdom