Easy as Six

by Arne Sommer

Easy as Six

[26] Published 10. August 2019. Updated 8. September 2019

This article has corrections and comments to my «Easy as Six» talk at PerlCon 2019 in Riga. I'll keep it updated.

Perl 6 → Raku
This article has been moved from «perl6.eu» as a result of the language rename in 2019. The content has not been updated.

Slide 13: Output

«say» was introduced in Perl 5 version 5.10, but must be enabled with one of these:

  • Add the line use feature 'say'
  • Add the line use v5.10 (or any higher version number)
  • Prefix it with «CORE::»; e.g. CORE::say "12"

Slide 14: Input

«get» isn't available in Perl 5.

The example doesn't make sense in Perl 6 (which has the «get» function), as the newline has already been removed.

The correct Perl 5 code is:

chomp(my $a = <>);

Or this, if we are paranoid:

chomp(my $a =<STDIN>);

If you do run the code on the slide in Perl 5, you get a funny result; $a is assigned the value "get". Certainly not what I anticipated...

Slide 15: In- and Output

The same issue with «get» as on the previous page.

The correct Perl 5 code is:

chomp(my $name = <>);

Slide 18: Reading a File

Remove the trailing «;» on the «while» line:

while (my $line = <$fh>)

The Perl 6 code should use «$_»:

do-something($_) for "filename".IO.lines;

Slide 50: Sequences

It is correct that «you cannot bind to an array (@values)», but assignment works:

my @values = 1 ... Inf;

Slide 51: Common Sequences

It is possible to specify the rule for calculating the next value.

The Show Off Example is the Fibonacci Sequence, where the two first numbers are 0 and 1, and after that any given number is the sum of the two numbers before it in the sequence.

Using placeholder variables:

my $fibs := (0, 1, { $^a + $^b } ... *);  

Even more compact (but also quite unreadable):

my $fibs := (0, 1, * + * ... *);

Any operator will do, and multiplication looks really nice (in an obfuscated way):

my $something := (1, 2, * * * ... *);
say $something[^10];
(1 2 2 4 8 32 256 8192 2097152 17179869184)