in reply to bit-wise

Hi rir,

For my own tastes, I would use integers and masks, in the "C" style.  Of course, my background is in "C", so you might call me biased.

For example, here's a simple example of clear_bit and set_bit using a mask and a bit index:

#!/usr/bin/perl -w # Strict use strict; use warnings; # Test code my $mask = 0b11001011; clear_bit($mask, 1); clear_bit($mask, 2); clear_bit($mask, 3); clear_bit($mask, 4); $mask = 0b11001000; set_bit($mask, 1); set_bit($mask, 2); set_bit($mask, 3); set_bit($mask, 4); # Subroutines sub clear_bit { my ($mask, $bit_index) = @_; printf "TFD> mask 0b%08lb\n", $mask; $mask &= ~(1 << ($bit_index - 1)); printf "TFD> mask 0b%08lb\n\n", $mask; } sub set_bit { my ($mask, $bit_index) = @_; printf "TFD> mask 0b%08lb\n", $mask; $mask |= (1 << ($bit_index - 1)); printf "TFD> mask 0b%08lb\n\n", $mask; }

The lines containing "TFD" are temporary debugging statements which can be removed once you've verified that the code is doing what you want.

Of course, if you want to use names in place of the bit_index, you could either pass the string (character) containing the name "1" - "9", and convert it back to an integer, or (where necessary) you could pass a hash containing the names (bit indices) you wish to operate on.

I'm sure you can write the rest of the subroutines, if this is the route you decide to go.  (But feel free to ask if you need more help or suggestions!)


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/