Mark J. Reed wrote:
> Possibly a FAQ, but is there a simple way of asking if an item is
> contained in an array? I know of $x ~~ any(@array) and @array.grep({
> $_ ~~ $x}), but those both seem a bit complicated for a conceptually
> simple test, so I'm wondering if I'm missing something.
Note that grep doesn't have to take a closure, but can also take just
the value you're looking for...
> my @x = 1,2,3; say ?@x.grep(2); say ?@x.grep(4);
1
0
Though more efficient would be:
> my @x = 1,2,3; say ?@x.first(2); say ?@x.first(4);
1
0
I still prefer the junction way though. :-)
/jnthn
Thread Previous
|
Thread Next