in reply to What A Wonderful World: Bitmasks!
Also, the bitwise operators aren't playing the "there's no difference between a string and a number" game in Perl very well:
perl -wle 'print +("30" | "50") == (30 | 50) ? "Yes" : "No"' No
Forgetting that commandline arguments, or regex captures are strings, even if they only contain numbers will bite you sooner or later. And no use of strict or warnings is going to catch that for you - Perl will just think you are doing a string-wise AND or OR.
If I work with bitfields, I tend to prefer bitstrings, and get the individual bits out of them with vec. This will save memory as well, is more flexible (instead of 2 values, you can opt for 4, 8, 16, etc as well), and doesn't have the idiosyncrasies you have with the bitwise operators.
Abigail
|
---|