Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: bit array comparison

by Athanasius (Archbishop)
on Oct 23, 2019 at 03:05 UTC ( [id://11107872]=note: print w/replies, xml ) Need Help??


in reply to Re^2: bit array comparison
in thread bit array comparison

my $i_cnt = () = sprintf("%b", $i) =~ /1/g; my $u_cnt = () = sprintf("%b", $u) =~ /1/g;

Minor point: for simple counting, tr/// (the transliteration operator) is preferred over m//g because it’s more efficient; also, the syntax is cleaner:

my $i_cnt = sprintf('%b', $i) =~ tr/1//; my $u_cnt = sprintf('%b', $u) =~ tr/1//;

Hope that’s of interest,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found