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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.