📘 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”

📘 Prefix operator + in Perl 6

+ is the unary plus operator, which casts its operand to the numerical context. The action is equivalent to the call of the Numeric method. my Str $price = ‘4’ ~ ‘2’; my Int $amount = +$price; say $amount;        # 42 say $price.Numeric; # 42 We will see one of the important use cases of … Continue reading “📘 Prefix operator + in Perl 6”

📘 Method postfix operator .+ in Perl 6

.+method makes an attempt to call all the methods with the given name on an object. This may be used, for example, when an instance is a part of the hierarchy of objects and its parent also has a method with the same name. More on the classes and class hierarchy in Chapter 4. class … Continue reading “📘 Method postfix operator .+ in Perl 6”

📘 Prefix operator ++ in Perl 6

++ is a prefix operator of increment. First, an increment is done, and then a new value is returned. my $x = 41; say ++$x; # 42 The increment operation is not limited to working only with numbers. It can also handle strings. my $a = ‘a’; say ++$a; # b A practical example is … Continue reading “📘 Prefix operator ++ in Perl 6”

📘 Prefix operator ^ in Perl 6

^ is a range-creating operator or the so-called upto operator. It creates a range (which is an object of the Range type) from 0 up to the given value (not including it). .print for ^5; # 01234 This code is equivalent to the following, where both ends of the range are explicitly specified: .print for … Continue reading “📘 Prefix operator ^ in Perl 6”