Perl 6 Basics Tablet: Revision 18
1st law of language redesign: Everyone wants the colon for their particular syntax.
Basics doesn't mean here easy but fundamental. Which mostly translates to how to format and reformat data (numbers, strings and more).
Please note that any Perl 6 source code is treated as unicode by default. Also use strict; and use warnings; are enabled implicitly.
Unless you use blocks, a Perl program executes one statement after another in linear progression. They have to be separated by a semicolon (;), except before and after a closing curly brace, where it is optional.
Spaces and Indentation
Perl doesn't care about indentation. And spaces are still in many places without meaning. However these have become fewer.
Like in Perl 5 and many other languages of its league a "#" tells the compiler to ignore the rest of the line.
Konverting into numerical context means still: take from left to right all digits and other characters, up to the first char that clearly don't belong to a number definition and stop there.
A single underscore is allowed only between any two digits in a literal number, like:
$people = 3_456_789; # same as 3456789
0b binary - base 2, digits 0..1
General Radix Form
:10<42> # same as 0d42 or 42
v1.2.3 # okay
$float = 60.2e23 # becomes automatically 6.02e24
To distinguish them from a division operation, you have to groupe them with braces.
As always, .perl gives you an almost source like code formatting which results here in 3/7. Adding .nude you get (3/7), the nude source code. There are 2 different immutable value types representing both rational number. FatRat has unlimited precision and Rat has just enough to be evaled into a Real type. When you explicitly type a variable to one o them, the braces become optional.
my Rat $other_pi = 22/7;
Quoting is like regular expression a sublanguage inside the main language with it's own syntactical rules. It is parsed by a special grammar as to be found in the special variable $~Q. The operator with the same name (the generic quoting operator) does almost nothing, just provides a mechanism to mark the beginning and end of text sequence. The examples in this chapter use almost every time slashes for that purpose, but any not alphanumerical character or pair of matching (bracing) character can be used as well.
Q /.../ or Q |...| or Q *...* or Q "..." or Q[...] ...
An extended delimiter mechanism is delivered by heredocs.
Inside of these delimiters, every character will be taken literally. Any additional meaning has to be added by quoting adverbs. Most of them have a short and a long name and some of the most useful have an additional syntax that replaces them altogether with the Q operator.
No matter which string delimiter is chosen, sometimes he has to occur as a literal character inside the string too. In that case use single quotes with the adverb :single or one of the following aliases, from which ' ' ist maybe the best know. Its also the shortest and easy to understand, but don't allow to add other adverbs.
Q :single /.../;
Inside single quotes the backslash (\) "quotes" meaning: he liberates the following character from his special meaning. Or to put it simple \\ translates (or interpolates) to \ and \' to '. For anything more you need additional adverbs.
'Welcome in Larry\'s madhouse'
The following adverbs with their short or long version allow a very fine grained definition what to interpolate.
:b aka :backslash # control character (implies at least :q)
Q :b /\t\n/; # tab and new line character
Double quoting combines all the previous mentioned adverbs, thatswhy all the following are synonymous.
Q :s, :a, :h, :f, :c, :b /.../;
But further adverbs can also be added using q/.../ or qq/.../.
Q :words /.../;
Q :quotewords /.../;
my @steps = <one two three>;
Are now normal quoted strings, only with a special delimiter.
Q :to 'EOT';
To make templates in which variables and closures are evaluated, take the normal double quote and just add the adverb for the heredoc delimiter or define with other adverbs what exactly you want to have evaluated.
Q :path /.../;
rx// aka Q :regex //
The .perl method is a built in Data::Dumper (pretty printer) which gives you structured data the way you write it in perl source code.
moved from core language to a module.