Reputation: 43673
Why the smartmatch operator ~~
says that 0
is not in (0, 5..100)
?
print ((0 ~~ (0, 5..100)) ? "Y" : "N");
N
Test it here.
Upvotes: 3
Views: 126
Reputation: 385897
Don't use the broken smart-match operator. 0 ~~ ...
is specifically one of the reasons it's considered broken.
Use
grep { $_ } 0, 5..100
or
use List::Util qw( first );
first { $_ } 0, 5..100
Upvotes: 2
Reputation: 118605
Make the right hand side an array reference
print ((0 ~~ [0, 5..100]) ? "Y" : "N");
or a named array
@a = (0, 5..100);
print ((0 ~~ @a) ? "Y" : "N");
or a ... whatever this is called (anonymous named array?)
print ((0 ~~ @{[0,5..100]}) ? "Y" : "N");
(0,5..100)
is a list but it is not an array, and this is one of the places where the distinction is important.
Upvotes: 5