In mathematics (i.e. boolean algebra) it is common to denote * for and and + for or IFF the alphabet is restricted to boolean values 0 and 1.

NOTE: 1 + 1 is mapped to 1 there.

This works in Perl somehow. (1+1 =2 is still true)

But don't ! It's not recommended ... rather a workaround in languages without boolean operators.²

Just sketch the truth table to see how it works.

Better use && and || instead.

> Y = (A & B)

that's definitely wrong, because & is for a bitwise and not a logical.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

UPDATE

to elaborate more: the standard false value in Perl is not 0 but empty string '' . While the latter will be evaluated to 0 in arithmetic operations it might cause a confusion.

DB<7> print !!0 DB<8> print !!1 1

footnotes

²) and only for simple cases, b/c you risk a number overflow when multiplying true values.

> perl -E "say ((1+1) * (1+1) * (1+1));" 8

In reply to Re: Boolean operation: (A & B) vs (A * B) by LanX
in thread Boolean operation: (A & B) vs (A * B) by Anonymous Monk

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.