#!/usr/bin/perl6 use v6; # Creating an array # see also S09 my @names = ('foo', 'bar', 'baz'); @names.perl.say; my @others = qw(foo bar baz); @others.perl.say;
#!/usr/bin/perl6 use v6; my @names = qw(foo bar baz); sub commify_series { # @_.perl.say; (@_ == 0) ?? '' !! (@_ == 1) ?? @_[0] !! (@_ == 2) ?? join(" and ", @_) !! join(", ", @_[0 .. (@_-2)], "and " ~ @_[*-1]); } # TODO due to a parsing bug in Rakudo this ; is required here ; say commify_series(|@names); @names.pop; say commify_series(|@names); @names.pop; say commify_series(|@names); # TODO: this should also work, but then we have to enable the @_.perl.say in the sub # say commify_series(@names);
#!/usr/bin/perl6 use v6;
Quite similar to how it is done in Perl 5 using a for loop, though the syntax of creating an array from a list of words has changed from qw to be <>
my @names = <foo bar baz>; for @names -> $name { say $name; }
This is quite similar to the same code in Perl 5.
my @names = <foo bar baz>; my @more_names = <moo barney>; say @names.perl; say @more_names.perl; push @names, @more_names; say @names.perl;
my @names = <foo bar baz>; say @names.perl; @names = reverse @names; say @names.perl;
To install Perl6::Cookbook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl6::Cookbook
CPAN shell
perl -MCPAN -e shell install Perl6::Cookbook
For more information on module installation, please visit the detailed CPAN module installation guide.