@ARGV is an array of strings. Bitwise OR or AND of strings in Perl results in a byte-by-byte OR or AND. Compare:
$ perl -e "print 1 & 63, qq(\n)" 1 $ perl -e "print q(1) & q(63), qq(\n)" 0
As an integer bitwise AND, the result is 1. As a string bitwise AND, the result is 0. Why? As a string, ord("1") & ord("6") yields ord("0"). To try something cool, try:
$ perl -e "print q(a) & q(ab), qq(\n)" a
Similarily, ord("a") & ord("a") yields ord("a"). (The characters on the end don't count for bitwise AND since the strings have a different length, and Perl doesn't explicitly include the "\0" characters at the end)
Any time you have a scalar that may be in string context that you need to manipulate as a number, consider using a common expression such as '0+$scalar' to force it to have a numeric representation. @ARGV appears to be just such a case.
In reply to Re: Bit Shifting ?
by MarkM
in thread Bit Shifting ?
by mitd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |