paulgorman.org/technical

Perl 6

http://perl6.org/getting-started/ http://doc.perl6.org/language/5to6 http://doc.perl6.org/

On debian: apt-get install rakudo.

Perl 6 does not appear to be available in the FreeBSD 10.2 ports collection.

The downloads page describes building from source (https://perl6.org/downloads/)

Try ‘hello.p6’:

#!/usr/bin/env perl6
use v6;
say "Hello, Perl 6";
"Hello, Perl 6, object-oriented style".say
# A single line comment
#`{{
A multi-
line comment.
}}

Unlike Perl 5, method calls use a dot instead of ->, like: $foo.color

Unlike Perl 5, sigils are now invariable. This is huge. @array = [0, 3, 7]; @array[2]; # 7

Reading a file into an array: my @lines = “file.txt”.IO.lines;

Strict mode and warnings are on by default in Perl 6.

Since strict is in effect, variables are declared with ‘my’ for lexical local scope: my $x = ‘foo’; say “My x is $x.”;

(‘say’ is like ‘print’, but appends a platform-appropriate newline.)

To get user input, use ‘prompt’, which does ‘say’, reads STDIN, and chomps: my $answer = prompt “What the answer, fool? “;

Parens in Perl 6 are only for group, so a simple ‘if’ doesn’t need them: if $answer == ‘daffodil’ { say “Yes!”; }

We have multi-line comments. Any kind of bracket works following the #. #( A long comment. )

Basic variable types: my $scalar = ‘Foo’; say $scalar; my @list = (‘a’, ‘b’, ‘c’); say @list[1]; say @list[@list.end]; my %hash = (‘red’ => ‘apple’, ‘yellow’ => ‘banana’); say %hash{‘yellow’}; my @colors = %hash.keys; my @fruits = %hash.values;

http://www.perlfoundation.org/perl6/index.cgi%3Fperl_6_tutorial_part_1 http://perl6maven.com/tutorial/ http://search.cpan.org/dist/Perl6-Doc-0.36/lib/Perl6/Doc/Overview.pod