develooper Front page | perl.perl5.porters | Postings from February 2019

Re: New defined-match operator

Thread Previous | Thread Next
From:
Dan Book
Date:
February 21, 2019 17:32
Subject:
Re: New defined-match operator
Message ID:
CABMkAVW75LoJOoQTK5mOu8cyjGc07cyn2f5c19pfxP0PgB6Mog@mail.gmail.com
On Thu, Feb 21, 2019 at 7:13 AM David Cantrell <david@cantrell.org.uk>
wrote:

> We all know how convenient it is to write this:
>
>   $foo //= 'bar';
>
> instead of:
>
>   $foo = 'bar' unless(defined($foo));
>
> Well, wouldn't it be nice to be able to write this:
>
>   if($foo //~ /bar/)
>
> instead of:
>
>   if(defined($foo) && $foo =~ /bar/)
>
> Thoughts?
>

While I don't dislike the concept, the //= operator is just an assignment
form of the // operator and expands to $foo = $foo // 'bar' (with $foo only
being evaluated once). //~ does not fit in this construction. Perhaps it
could be something similar to the idea of the maybe-arrow operator - ?=~

-Dan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About