๐ŸŽ„ 9/25. More on X, .., and … in Perl 6

Welcome to Day 9 of the Perl 6 One-Liner Advent Calendar! On Day 6, we had a construct with a cross-operator, (999…100) X* (999…100). Today, weโ€™ll dive into a similar construction from November: 1..10 X* 1..10 It prints the items of the product table for the numbers from 1 to 10: (1 2 3 4 … Continue reading “๐ŸŽ„ 9/25. More on X, .., and … in Perl 6”

๐ŸŽ„ 8/25. Adding up even Fibonacci numbers in Perl 6

Welcome to Day 8 of this year’s Perl 6 One-Liner Advent Calendar. It is aboutย ยผ of the whole series, and donโ€™t forget that you can typeย ยผ instead of 0.25 in Perl 6! Today, we are solving problem 2 from Project Euler. The task is to find the sum of all even Fibonacci numbers below four … Continue reading “๐ŸŽ„ 8/25. Adding up even Fibonacci numbers in Perl 6”

๐ŸŽ„ 7/25. The joy of Unicode in Perl 6

Welcome to Day 7 of the Perl 6 One-Liner Advent Calendar! Today, weโ€™ll look at the month of March in the Perl 6 Calendar 2019: The code here is using three characters outside of the ASCII land. We can even add one more: say ฯ€ ร— $๐œŒยฒ In Perl 6, you can freely use Unicode … Continue reading “๐ŸŽ„ 7/25. The joy of Unicode in Perl 6”

๐ŸŽ„ 6/25. Testing palindromic numbers in Perl 6

Welcome to Day 6 of the Perl 6 One-Liner Advent Calendar! As promised yesterday, today weโ€™ll be solving problem 4 of Project Euler. Let me once again remind you that you can pause reading and solve the problem yourself first. My intention is to demonstrate the beauty of Perl 6 and Perl in general. So, … Continue reading “๐ŸŽ„ 6/25. Testing palindromic numbers in Perl 6”

๐ŸŽ„ 5/25. Whatโ€™s the date today in Perl 6?

Welcome to Day 5 of this lovely Perl 6 One-Liner Advent Calendar! Today, weโ€™ll answer the question of whatโ€™s the date today (and tomorrow we can talk about palindromes if you want). So, to print the answer, you can use the following line of Perl 6 code: DateTime.now.yyyy-mm-dd.say It looks transparent and prints the date … Continue reading “๐ŸŽ„ 5/25. Whatโ€™s the date today in Perl 6?”

๐ŸŽ„ 4/25. Working with big numbers in Perl 6

Welcome to Day 4 of the Perl 6 One-Liner Advent Calendar! Today, weโ€™ll look at the Problem 13 of Project Euler. Let me show a screenshot of it: Indeed, it looks huge, and the task is to find the first ten digits of the sum of a hundred integers, each consisting of 50 digits. Sounds … Continue reading “๐ŸŽ„ 4/25. Working with big numbers in Perl 6”

๐ŸŽ„ 3/25. Generating random integers in Perl 6

Welcome to Day 3 of the Perl 6 One-Liner Advent Calendar! Today, we will generate random numbers. You may ask, whatโ€™s the deal with it, isnโ€™t it a routine task to call a kind of a rand function? Well, in some sense, yes, but in Perl 6, you might prefer calling a method.  Letโ€™s look at the … Continue reading “๐ŸŽ„ 3/25. Generating random integers in Perl 6”

๐ŸŽ„ 2/25. Grepping dividable numbers in Perl 6

Welcome to Day 2 of the Perl 6ย One-Liner Advent Calendar! Today, weโ€™ll solve a nice task from Project Euler with number 1. Once again, let me warn you that the rest of the text contains a solution, so you are welcome to make a pause to think of your own solution first. But I am … Continue reading “๐ŸŽ„ 2/25. Grepping dividable numbers in Perl 6”

๐ŸŽ„ 1/25. Generating random passwords in Perl 6

Welcome to the first day of the brand new Perl6.Online Advent Calendar! This year, its theme is Perl 6 One-Liners (a pun from perl6.onliners). Thus, welcome to this yearโ€™s Perl 6 One-Liner Advent Calendar. The whole perl6.online blog was initially planned to be daily, so itโ€™s a great opportunity to keep the pace for at least another … Continue reading “๐ŸŽ„ 1/25. Generating random passwords in Perl 6”

๐Ÿ“˜ 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”

๐Ÿ“˜ Prefix operator temp in Perl 6

temp creates a temporary variable and restores its value at the end of the scope (like it does the local built-in operator in Perl 5). my $x = ‘x’; { ย ย ย  temp $x = ‘y’; ย ย ย  say $x; # y } say $x;ย ย ย  ย # x Compare it with the following operator, let.