If you wanted to use List::Util::first for AND and OR, these work:
sub AND { my $last; first {!($last = $_)} @_ or $last; } sub OR { my $last; first {($last = $_)} @_ and $last; }
Again, the little bit of yin-yang.

I note that the short-circuiting you mention isn't quite as good as the short-circuiting you get with the actual operators, since each element of the list will be evaluated prior to calling the function. So you don't have to traverse the entire list, but any function calls and assignments within the list will be executed.

I note also that you're just exchanging the && operator for a comma (plus the function calling semantics). I had thought that overloading the comma operator would be a clever alternative, but it turns out not to be overloadable.

Our functional-programming brethren might prefer the tail-recursive

sub OR { @_ > 1 ? shift || OR(@_) : shift; } sub AND { @_ > 1 ? shift && AND(@_) : shift; }
Update: tail-recursive ones were buggy.

Caution: Contents may have been coded under pressure.

In reply to Re: An infix fix by Roy Johnson
in thread An infix fix by tlm

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.