Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

by tye (Sage)
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")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://64008]
[stevieb]: everything depends on how the I2C hardware at the other end returns. Instead of forcing a user to bitshift, I think I'll add methods for read_word_big() and read_word_little() or something

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-07-22 00:21 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (336 votes). Check out past polls.