You can almost do this in Perl, but it requires sticking a method in UNIVERSAL (awful) and loading autobox::Core (because by default not everything is an object), both of which highly intrusive changes.

use autobox::Core; use Class::Null; sub UNIVERSAL::andand { return defined $_ ? $_ : Class::Null->new for +shift }

However, even with autobox loaded you cannot call methods on undef. So for all the intrusion you accepted for this it will still fail. You just have to be explicit:

for ( grep $_, $shop->ShopperDueDate ) { say $_->day_name() }

You can try to abstract this out a little, but then you get either a different kind of verbosity:

sub iftrue { for ( grep $_, $_[0] ) { $_[1]->() } } iftrue $shop->ShopperDueDate, sub { say $_->day_name() };

Or if you try to fix that it reads in the wrong order:

sub cond(&$) { for ( grep $_, $_[1] ) { $_[0]->() } } cond { say $_->day_name() } $shop->ShopperDueDate;

And don’t even think of “fixing” this with Filter::Simple. If source filters are the answer then you’re asking the wrong question. You will have mysterious bugs if you go down that route because source filters always break. How badly depends on filter in question; yours is a case where the type of breakage is bad.

What might (eventually) be possible is to implement something like this with Devel::Declare voodoo, which is (becoming) a macro system and therefore not prone to the problems of source filters.

Makeshifts last the longest.


In reply to Re: Is there an andand for Perl like there is in Ruby? by Aristotle
in thread Is there an andand for Perl like there is in Ruby? by frew

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.