develooper Front page | perl.perl5.porters | Postings from October 2015

Re: smartmatch needs your eyes

Thread Previous | Thread Next
From:
Tony Cook
Date:
October 6, 2015 20:48
Subject:
Re: smartmatch needs your eyes
Message ID:
20151006204833.GA12808@mars.tony.develop-help.com
On Tue, Oct 06, 2015 at 08:57:50PM +0100, Dave Mitchell wrote:
> On Tue, Oct 06, 2015 at 01:39:25PM -0400, Ricardo Signes wrote:
> > * Dave Mitchell <davem@iabyn.com> [2015-10-06T12:03:30]
> > > So for final clarity, is
> > > 
> > >     when (EXPR) {...}
> > > 
> > > intended to always be exactly equal to 
> > > 
> > >    if ($_ =~ EXPR) {...; break }
> > 
> > Yes.
> > 
> > > If so, how does one write something functionally equivalent to when(1)
> > > now?
> > 
> > when { $_ == 1 } { ... }
> 
> But by the definition above, that is equivalent to 
> 
>     if ($_ =~ ($_ == 1)) {...; break }

  when (FOO) { ... }

becomes

  if ( $_ ~~ FOO) { ...; break }

but

  when { FOO } { ... } # braces not parentheses

becomes

  if ( FOO ) { ...; break }

There's also postfix when { ... }

Tony

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