Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: using smartmatch for range matching

by ikegami (Patriarch)
on Nov 26, 2023 at 17:51 UTC ( [id://11155857] : note . print w/replies, xml ) Need Help??


in reply to using smartmatch for range matching

If you want to keep the $number ~~ [1416..1494] notation without the inefficiencies of it and the problems inherent with using smart-matching, you could use

in_range( $number, 1416, 1494 )

But I would use the following instead:

1416 <= $number <= 1494

Also is this depreciation of smartmatch definitive or is there a chance that the Perl devs will change their mind and keep it?

Its buggy due to a broken design, and it's being removed in 5.42.

5.10: Somehow introduced despite the known broken design.
5.10.1: Backwards incompatible change because it was so bad in 5.10.0. But didn't address the broken design. (That would be impossible without completely changing what the operator does.)
5.16: Becomes experimental (in the documentation).
5.18: Using experimental features now warn.
5.38: Becomes deprecated. It was announced it would be removed in 5.42.

There's a clear path towards removal. And the above severely understates the chaos the feature has caused. The feature and chaos resulted in the creation policies to make new features experimental, backed with the creation of a formal system for warning when experimental features are used. They also caused the policies for backwards compatibility and the breakage thereof to be formalized. Finally, the above doesn't mention the various pushes to have the failed experiment removed, attempts that were stymied by the presence of a large user base.

Replies are listed 'Best First'.
Re^2: using smartmatch for range matching
by choroba (Cardinal) on Nov 26, 2023 at 22:20 UTC
    > in_range( $number, 1416, 1494 )

    What module does it come from?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      It's a trivial sub you can write yourself:

      sub in_range { $_[1] <= $_[0] <= $_[2] }