First of all, what's with all the useless parens?
my @numbers = (2); => my @numbers = 2; my @other = (2); => my @other = 2; @numbers ~~ (2) => @numbers ~~ 2 my @empty = (); => my @empty;
my @numbers = 2; @numbers ~~ 2 being false is to be expected. It was necessary to make ~~ non-commutative to fix bugs. In this case, since you're comparing against a simple scalar, a scalar comparison is made. You want 2 ~~ @numbers.
As for when (()), it should give an error if it doesn't do anything useful. I'll see about reporting a bug. ( On second thought, empty list in scalar context returns undef. I don't think anything can be done about that. )
Finally, keep in mind that when you specify an array, it's a reference to the array that's provided to the match operator.
>perl -E"@a = qw(a b); say @a ~~ 2 ? 'match' : 'no match'" no match >perl -E"@a = qw(a b); say @a ~~ (0+\@a) ? 'match' : 'no match'" match
The idea might be to allow the following
>perl -E"@a = qw(a b); say \@a ~~ \@a ? 'match' : 'no match'" match
but it actually uses a different rule.
>perl -E"@a = qw(a b); @b = qw(a b); say \@a ~~ \@b ? 'match' : 'no ma +tch'" match
This might be improvable. I'll see about bringing this up too.
In reply to Re: smart match operator should be smarter!
by ikegami
in thread smart match operator should be smarter!
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |