=head1 Junctions Motivation: Ways to compare arrays via Junctions =cut use 5.0.10; use Perl6::Junction qw(any all one none); my @rainbow = qw(red orange yellow green blue indigo violet); if (any(@rainbow) eq 'indigo') { say "It's a go."; } =head1 Slices of Hash Motivation: Suppose you got a hash and you want a subset of the hash values. One can access those values via a hash slice. Mappings: function hash slice: hashes -> lists subset of keys |--> list of values. How: List the keys of the wanted values, but since the return is a list use @ instead of $ as the hash sigil. Example: Below =cut my %hash = qw( wednesday brown friday red saturday black ); my @weekend_hash = @hash{qw(friday saturday)}; print 'On the weekend she enjoys '; print join ', and ', @weekend_hash; print '.';
[download]
=pod Another example to show how one could set the values of a hash to a default value givens an array to act as the keys. =cut
my @grades = qw/ 0 1 2 3 /; my %student_count_by_grade; @student_count_by_grade{@grades} = (0) x 4;
[download]