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

Re: smartmatch needs your eyes

Thread Previous | Thread Next
Ricardo Signes
September 21, 2015 13:36
Re: smartmatch needs your eyes
Message ID:

This whole subthread is rebuilding my resolve.  Plain scalars should go pound
sand.  I don't believe I'll see a way to use them on the rhs of ~~ that will be

I think we're better off with helpers to build tests, like Smart::Match.

  sub smartgrep ($test, @items) { return grep { $_ ~~ $test } @items; }

If we want the test to be numeric, we can call:

  smartgrep num(4), @input;

Making that faster than 0+@input subroutine calls should be possible in the
future if someone decides it's worth doing.

Meanwhile, we have:

  when { $_ == 1 } { ... }

...which is still shorter than:

  if ($_ == 1) { ...; break; }

Also, if we disallow "when (5)" now, it can be enabled later, but if we allow
it now, we're stuck with it.

That was the plan when I first posted to this thread, and I don't know why I
got distracted by this idea that I'd already dismissed ages ago.


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