in reply to [Perl6] Can i put a operator in container
You can now use the minus operator too compute the set differences between the two hashes.multi sub infix:<-> (%main, %dict) { my %difference; for %main.keys -> $word { %difference{$word} = 1 unless %dict{$word}:exists; } return %difference; }
Update: I did not have time to complete when I wrote the above.
Now, assuming you have a %book-words hash containing all the different words in a given book, and a %dictionary hash, you could build a hash with all the words in the book and not in the dictionary:
Perl 6 does not define the minus operator between hashes, but it can easily be added to the language as shown above, and Perl 6 won't get confused.my %missing-words = %book-words - %dictionary;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [Perl6] Can i put a operator in container (Perl 6)
by Laurent_R (Canon) on Jul 10, 2017 at 17:45 UTC | |
|
Re^2: [Perl6] Can i put a operator in container (Perl 6)
by freakcoco (Sexton) on Jul 11, 2017 at 04:30 UTC | |
by raiph (Deacon) on Jul 11, 2017 at 22:33 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |