develooper Front page | perl.perl5.porters | Postings from August 2012

Re: fixing smartmatch (again (still))

Thread Previous | Thread Next
Jesse Luehrs
August 28, 2012 16:02
Re: fixing smartmatch (again (still))
Message ID:
On Tue, Aug 28, 2012 at 06:52:35PM -0400, David Golden wrote:
> On Tue, Aug 28, 2012 at 5:06 PM, Jesse Luehrs <> wrote:
> > I think people will have fewer reservations about accepting weird
> > special cases like this for a keyword-based control structure
> > (especially considering the precedent set by while (<>), etc) than for
> > an infix operator (since it will be a weird special case either way -
> > "why can i do '$foo ~~ 1', but not '$a = 1; $foo ~~ $a'?".
> >
> >
> The opportunity for confusion exists either way.  My suggestion is to
> change *one* thing -- smartmatch -- instead of *two* things -- smartmatch
> and when.
> Then all people have to know/relearn is the smartmatch table, not the
> smartmatch table *and* the special case rules for when.

But this *is* a change to when, that's what I'm saying. From perlsyn:

    Exactly what the EXPR argument to "when" does is hard to describe
    precisely, but in general, it tries to guess what you want done.
    Sometimes it is interpreted as "$_ ~~ EXPR", and sometimes it does
    not. It also behaves differently when lexically enclosed by a
    "given" block than it does when dynamically enclosed by a "foreach"
    loop.  The rules are far too difficult to understand to be described
    here.  See "Experimental Details on given and when" later on.

For instance, currently "when ($a && $b)" means
"when ($_ ~~ $a && $_ ~~ $b)".


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About