Determine whether an array contains a value

AUTHOR

Fyodor Sizov

DESCRIPTION

What's interesting here?

  • Use of "eq" operator and any(@array)

  • eq any(@arr) can be used both for strings and integers


use v6;

my @arr = <the quick brown fox 5 2 9>;
say 'fox' eq any(@arr) ?? 'YES' !! 'NO'; # YES
say 'dog' eq any(@arr) ?? 'YES' !! 'NO'; # NO
say 3 eq any(@arr) ?? 'YES' !! 'NO'; # NO
say 2 eq any(@arr) ?? 'YES' !! 'NO'; # YES

# Local Variables:
# mode: perl6
# indent-tabs-mode: nil
# perl6-indent-offset: 4
# End:
# vim: expandtab shiftwidth=4 ft=perl6

See Also

bottles.pl

99 bottles of beer

combinations.pl

Combinations

malware_analysis.raku

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.