Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-28 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found