gpt4 book ai didi

for-loop - perl6/落语 : dereferencing-question

转载 作者:行者123 更新时间:2023-12-02 05:31:42 24 4
gpt4 key购买 nike

#!perl6
use v6;

my $list = 'a' .. 'f';

sub my_function( $list ) {
for ^$list.elems -> $e {
$list[$e].say;
}
}

my_function( $list );

首先我在 perl5 风格中尝试了这个,但没有成功:

for @$list -> $e {
$e.say;
}
# Non-declarative sigil is missing its name at line ..., near "@$list -> "

我怎么能在 perl6 中做到这一点?

最佳答案

在 Perl 6 中,您不会像这样取消引用变量。只需使用 for $list

但这可能不会做您想做的事。 'a'..'f' 在 Perl 6 中不构造列表,而是构造称为 Range 的内置数据类型。您可以使用 say $list.WHAT 进行检查。要将它变成一个列表并遍历每个元素,您可以使用 for $list.list

关于for-loop - perl6/落语 : dereferencing-question,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5031737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com