in reply to bitwise operators

This is dark art and not likely to be of use to you any time soon. I've never used it but I actually do have a usage example at the end of this post.

First, in order to make the answer to your question more clear, let's look at the question you did NOT ask. As the docs state, there is a difference between 123.45 & 234.56 and "123.45" & "234.56". In the first case, the two numbers will be truncated to integers and then the two values 123 and 234 will (in effect) be taken in their binary representation and ANDed. (Doing these in my head as I go -- I may slip a bit or two.) Thus:

123 decimal = 01111011 binary 234 decimal = 11101010 binary ^^ ^ ^ <-- ANDing to find overlap 106 decimal 01101010 result

So the result of evaluating 123.45 & 234.56 can be thought of as depending on the binary representation of (the integer portion of) each number taken as a whole.

So far so good...

In the case of "123.45" & "234.56", the two values are evaluated character-by-character according to the ASCII values of each character. So, while the previous case only works with numbers, in this case you could just as easily say "ABCD" & "gHiJ".

I won't reproduce the entire ASCII table, but here are the values for the numerical digit characters. And while we're at it, lets show their binary representations. We will need them in a minute.

'0' = char 48 = 110000 binary '1' = char 49 = 110001 binary '2' = char 50 = 110010 binary '3' = char 51 = 110011 binary '4' = char 52 = 110100 binary '5' = char 53 = 110101 binary '6' = char 54 = 110110 binary '7' = char 55 = 110111 binary '8' = char 56 = 110100 binary '9' = char 57 = 110101 binary

Note in each case we are talking about e.g. the character 7. Not the value seven (as in seven things).

So... when Perl sees "123.45" & "234.56", it takes each string character-by-character comparing (so to speak) their binary representations. So, for the first character of each string:

'1' = char 49 = 110001 binary '2' = char 50 = 110010 binary ^^ <-- ANDing to find overlap '0' = char 48 = 110000 binary

For the second character of each string:

'2' = char 50 = 110010 binary '3' = char 51 = 110011 binary ^^ ^ <-- ANDing to find overlap '2' = char 49 = 110010 binary

And so on until we get "020.44".

Now the folks who designed the ASCII table did a clever thing. They set up the table so that the bottom four bits of the number characters were also the binary values for each digit. So for the character '5':

'5' = char 53 = 110101 binary ^^^^ <--Note these bits

and for the value five (as in five things):

5 = 0101 binary

so when we start ANDing and ORing these they act as if we were ANDing and ORing each digit's value (and not simply its ASCII assignment) digit-by-digit. If we do bitwise comparisons of strings of digits, we can (within certain limits) pretend we are ANDing or ORing the values of each digit and not just their ASCII assignments. Cute! But watch out. If you say "1234" & "39", Perl will start with the left-most character in each string. It will not compare the tens digit against the tens digit.

So what good is all this? Danged if I know!... Actually I can think of a few uses. Here's one example. First, some more ASCII values:

'A' = char 65 = 01000001 binary 'B' = char 66 = 01000010 binary 'a' = char 97 = 01100001 binary 'b' = char 98 = 01100010 binary

Note that 'A' and 'a' differ by 32. And as chance would have it, ASCII character 32 (which is the space character: ' ') has a binary representation with just one single '1' bit set. This means that it makes a useful binary mask (those clever ASCII people again). And the complement of character 32 (for our purposes) is character 95 which is the underscore. So here are a pair of clumsy upper- and lower-case translators:

print 'AbCdEfGh' | ' ', "\n"; print 'aBcDeFgH' & '________', "\n";
Which prints:
abcdefgh ABCDEFGH

And that, I suppose, is quite enough about bitwise comparison of strings for now... HTH

Update: Many of the responses to this thread play around with the upper/lower-case trick.