Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Comparing a value to a list of numbers (in via smartmatch)

by LanX (Cardinal)
on Jan 29, 2021 at 16:47 UTC ( #11127646=note: print w/replies, xml ) Need Help??


in reply to Comparing a value to a list of numbers

well, for completeness:

There is smartmatch ~~ (sometimes) acting like an in operator

DB<24> $x=5 DB<25> p $x ~~ [1,2,5,6,9,10,41..56] 1 DB<26> $x=0 DB<27> p $x ~~ [1,2,5,6,9,10,41..56] DB<28>

but

WARNING: Smartmatch is experimental

so you'd need to deactivate the warning and hope it'll never vanish (at your risk)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Comparing a value to a list of numbers (in via smartmatch)
by Marshall (Canon) on Jan 30, 2021 at 02:27 UTC
    I personally would not use the smartmatch operator for anything.
    I did some experimenting with this experimental operator and found out that it is "too smart for me!". I could not accurately predict what this thing would actually do!
      I agree, but there is a real need for an "in"-operator like in other languages.

      I hope this aspect will survive somehow and I listed it for completeness with full warning.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11127646]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2021-06-13 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (54 votes). Check out past polls.

    Notices?