in reply to What A Wonderful World: Bitmasks!

I wouldn't overrate the uses of bitmasks. Sure, they save memory, bit in situations where memory is that important, you probably shouldn't have used Perl in the first place. Furthermore, bitmasks aren't completely portable; the number of bits in an integer isn't the same everywhere.

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