Ugh. The documentation on & in perlop is split into two, one half under "Bitwise And" and the other half under "Bitwise String Operators" and neither half even hints at how & can do both of these different operations.
So, I guess it is somewhere else in the documentation (or perhaps even only in earlier versions of the documentation) where I have read that & does bit-wise integer 'and' if either of the two arguments have been recently used as a number. However, if both arguments have only ever been used as strings, then bit-wise string 'and' is done.
@ARGV contains the string arguments given on the command line. This (the bit-wise operators, & and |) is one of the quite rare cases where this kind of tricky detail matters. I'd probably change your code to use:
my $arg00 = 0 + shift @ARGV;
to force $arg00 to be treated as a number.
Or you can force it right next to the operator:
(0+$arg00) & $arg01
- tye
In reply to Re: bit-wise operation (+)
by tye
in thread bit-wise operation
by toro_the_third
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |