@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

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.