in reply to Re: Flipping bits and using flags
in thread Flipping bits and using flags

I'd be inclined to use 1 << $bit instead. The result is exactly the same, but shift has bit semantics rather than the arithmetic semantics of **.

For the OP's question ord is probably not required. The implication of the OP's post is that there is already a $flags variable so the test is:

$flags & (1 << $bit) ? "on" : "off"

It is important for OP to note that $bit ranges from 0 (least significant bit) to 4 (most significant of 5 bits) and that the expression 1 << $bit generates the values 1, 2, 4, 8 and 16.


DWIM is Perl's answer to Gödel