>>>>> "CH" == Chap Harrison <c...@pobox.com> writes:

  CH> I'm almost embarrassed to ask this, but I can't figure out a
  CH> simple way to construct a switch ('given') statement where the
  CH> 'when' clauses involve bit-testing.  Here's the only way I've
  CH> figured out to build a switch statement that does the trick.  It
  CH> seems unusually wordy, which makes me think there must be a
  CH> simpler way to test for certain bit combinations.  Any
  CH> suggestions?

  CH>         when ( ($_ & $one_three) == $one_three ) {  # bits one and
  CH>         three are on

don't put comments on the same line as code. it can make it line wrap
like above.

anyhow, some boolean hacking does the trick. this seems to work.


         when ( !(~$_ & $one_three) )

you invert the flag bits and then and against the test mask. if that is all
0's (tested with !) then your bits were set.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to