在独立例程中§
有关sub prompt,请参阅主要文档 in context
multi prompt()multi prompt()
Prints $msg
to $*OUT
handle if $msg
was provided, then gets a line of input from $*IN
handle. By default, this is equivalent to printing $msg
to STDOUT, reading a line from STDIN, removing the trailing new line, and returning the resultant string. As of Rakudo 2018.08, prompt
will create allomorphs for numeric values, equivalent to calling val prompt
.
my = prompt "What's your name? ";say "Hi, $name! Nice to meet you!";my = prompt("Say your age (number)");my Int = ;my Str = ;
在上面的代码中,如果正确输入数字,$age
将被鸭子类型化为同形异位词 IntStr
。