perl - perl6/rakudo: How can I change the data-type of a variable? -
#!perl6 use v6; $m = 70; $n = 30; ( $m div $n ).say;
the first examples works, second doesn't. suppose it's because in second example variable-values strings. if guess right, how change string-variables integer-variables?
#!perl6 use v6; $m = '70'; $n = '30'; ( $m div $n ).say; # no applicable candidates found dispatch 'infix:<div>'. # available candidates are: # :(int $a, int $b) # in main program body @ line 7:./perl5.pl
you can manually cast int
( $m.int div $n.int ).say;
actually have hoped prefix:<+> work in
( +$m div +$n ).say;
but "num"ifies , sig requires "int", not sure if should way or not.
update: +$m
works.
Comments
Post a Comment