Raku By Example
View me onGitHub
## 差集
my @logname = lines "qr.txt".IO;
my @mysql = lines "ifo.txt".IO;

my $diff = @logname.unique (&) @mysql.unique;

.say for $diff.keys.sort;

## 交集
sub MAIN(Str $file1, $file2) {
    my @logname = lines "$file1".IO;
    my @mysql = lines "$file2".IO;
    my $diff = @logname.unique (&) @mysql.unique;
    .say for $diff.keys.sort;
}

## minmax
my @a = [1,2,3,4,5,6,7,9,10,12];
my $a = @a.minmax;
($_@a)?? .say !! "".say for $a.flat;

## reduce
say [-] <10 5 3>;
say [-] 10;

## elem

my $keywords = set <if for unless while>; # create a set

sub has-keyword(*@words) {
    for @words -> $word {
        return True if $word (elem) $keywords; # 依次检查数组中的元素是否属于集合 $keywords
    }
    False;
}

say has-keyword 'not', 'one', 'here';       # False
say has-keyword 'but', 'here', 'for';       # True

# 属于

my @a = [1,2,3,4,5,6,7,9,10,12];
my $a = @a.minmax;
($_@a)?? .say !! "".say for $a.flat;