Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

For defined-or we already have //.

As far as the other two go, take a look at PerlX::Perform which I believe should allow you to do defined-and and defined-dereference, albeit with more verbose syntax.

For example, imagine that $bob->spouse might return a Person object, or might return undef if Bob isn't married. Then PerlX::Perform allows:

$bobs_wifes_name = perform { $_->name } wherever $bob->spouse;

If the wherever expression evaluates to undefined, then the perform keyword returns undef (or the empty list if called in list context). If the wherever expression evaluates to a defined value (even if that value is false) then that value is assigned to $_ and the perform block is triggered.

PerlX::Perform also offers an alternative syntax which works more or less the same way. Note that the alternative syntax uses a comma, whereas the syntax above does not.

$bobs_wifes_name = wherever $bob->spouse, perform { $_->name };

So your A :&& B can be written as:

wherever A, perform {B}

And your A:->B can be written as:

wherever A, perform {$_->B}

Do give PerlX::Perform a try. Patches for improved performance, or more sugary syntax are likely to be accepted.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Perl5 Language Extension: Definedness-Triggered Shortcut Operators by tobyink
in thread RFC: Perl5 Language Extension: Definedness-Triggered Shortcut Operators by martin

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 sharing their wisdom with the Monastery: (4)
As of 2024-04-19 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found