📘 Variables in Perl 6: Introspection

Due to the mechanism of introspection, it is easily possible to tell the type of the data living in a variable (a variable in Perl 6 is often referred as a container). To do that, call the predefined WHAT method on a variable. Even if it is a bare scalar, Perl 6 treats it internally … Continue reading “📘 Variables in Perl 6: Introspection”

📘 Int type in Perl 6

The Int type is intended to host integer variables of arbitrary size. For example, no digit is lost in the following assignment: my Int $x =     12389147319583948275874801735817503285431532; say $x; A special syntax exists for defining integers with an other-than-10 base: say :16<D0CF11E0> Also, it is allowable to use the underscore character to separate digits … Continue reading “📘 Int type in Perl 6”

📘 Prefix operators ! and not in Perl 6

Prefix operators are those that come in front of their operands. Obviously, prefix operators require only one operand. In some cases, the symbol of the operation can be used as an infix operator when it stands between two operands. ! is the Boolean negation operator. say !True;     # False say !(1 == 2); # True … Continue reading “📘 Prefix operators ! and not in Perl 6”

📘 Frequently used special variables in Perl 6

The $_ variable is the one similar to that in Perl 5, which is the default variable containing the current context argument in some cases. Like any other variable, the $_ is an object in Perl 6, even in the simplest use cases. For example, the recent example .say for @*ARGS implicitly contains the $_.say … Continue reading “📘 Frequently used special variables in Perl 6”

📘 Hello, World! in Perl 6

The Perl 6 compiler can either read a programme from a file or from the content of the -e command line switch. The simplest “Hello, World!” programme looks like this: say “Hello, Perl 6!”; Save it in a file and run: $ perl6 hello.pl Hello, Perl 6! Alternatively, you may use the -e option: $ … Continue reading “📘 Hello, World! in Perl 6”

📘 Array in Perl 6

The Array variables (i.e., all the variables starting with the @ sigil) are equipped with a couple of simple but rather useful methods. my @a = 1, 2, 3, 5, 7, 11; say @a.Int; # array length say @a.Str; # space-separated values If you print an array, you get its value as a space-separated list … Continue reading “📘 Array in Perl 6”

📘 Built-in types in Perl 6

Perl 6 allows using typed variables. To tell the compiler that the variable is typed, you simply need to name the type while declaring the variable. Some of the types available in Perl 6 are obvious and do not need comments: Bool, Int, Str Array, Hash, Complex Some might require a small comment: Num, Pair, … Continue reading “📘 Built-in types in Perl 6”

📘 Variables in Perl 6: Twigils

In Perl 6, a variable name may be preceded by either a single-character sigil, such as $, @ or %, or with a double character sequence. In the latter case, this is called a twigil. The first character of it means the same thing that a bare sigil does, while the second one extends the … Continue reading “📘 Variables in Perl 6: Twigils”