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

Re: New defined-match operator

Thread Previous
From:
Elizabeth Mattijsen
Date:
February 21, 2019 12:18
Subject:
Re: New defined-match operator
Message ID:
A314C132-285D-441E-81C2-212C368EE332@dijkmat.nl
sub infix:<//~>($a,$b) { defined($a) && so $a ~~ m/$b/ }

/me ducks

> On 21 Feb 2019, at 12:55, 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?
> 
> -- 
> David Cantrell | Enforcer, South London Linguistic Massive

Thread Previous


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