Perl6 / rakudo: How can I change the data type of a variable?

#!perl6
use v6;

my $m = 70;
my $n = 30;

( $m div $n ).say;

The first examples work, but the second does not. I guess this is because in the second example, value variables are strings. If my assumption is correct, how can I change variable variables to integer variables?

#!perl6
use v6;

my $m = '70';
my $n = '30';

( $m div $n ).say;


# No applicable candidates found to dispatch to for 'infix:<div>'. 
# Available candidates are:
# :(Int $a, Int $b)

#   in main program body at line 7:./perl5.pl
+3
source share
2 answers

You can always manually add to Int

( $m.Int div $n.Int ).say;

In fact, I would hope that the prefix: <+> will work as in

( +$m div +$n ).say;

But these are just "Num" ifies, and sig requires "Int", I'm not sure if this should be so or not.

UPDATE: +$mnow works.

+7
source

, ( Int, ). Perl 6 , . (: , : , , . Str).

, +$m , .

, $variable.Typename, , Rakudo .

+4

Source: https://habr.com/ru/post/1793220/


All Articles