Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

(tye)Re2: Counting number of characters in a string

by tye (Cardinal)
on Mar 13, 2001 at 02:54 UTC ( #64008=note: print w/ replies, xml ) Need Help??


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


Comment on (tye)Re2: Counting number of characters in a string
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://64008]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2015-07-29 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls