in reply to bitmask check

As others have said, there isn't anything wrong with your code; I just wanted to add another common method for doing bit tests in to the mix. This sub will test for a single bit being set.
sub bit_test { my ($value, $bit) = shift; return $value & (1 << $bit); }

Replies are listed 'Best First'.
Re^2: bitmask check
by Anonymous Monk on Nov 12, 2013 at 21:01 UTC

    I know this is 2 years old but I stumbled on this and it might similarly confuse someone else.

    THIS is the corrected bit_test subroutine

    sub bit_test { my ($value, $bit) = @_; return $value & (1 << $bit); }

    Original code would only test the first bit position (1 << 0).