gpt4 book ai didi

replace - 替换 : replacement evaluation

转载 作者:行者123 更新时间:2023-12-04 01:05:02 26 4
gpt4 key购买 nike

如果替换在变量中传递,第一次和第二次替换是否等效?

#!/usr/bin/env perl6
use v6;

my $foo = 'switch';
my $t1 = my $t2 = my $t3 = my $t4 = 'this has a $foo in it';

my $replace = prompt( ':' ); # $0

$t1.=subst( / ( \$ \w+ ) /, $replace );
$t2.=subst( / ( \$ \w+ ) /, { $replace } );
$t3.=subst( / ( \$ \w+ ) /, { $replace.EVAL } );
$t4.=subst( / ( \$ \w+ ) /, { ( $replace.EVAL ).EVAL } );

say "T1 : $t1";
say "T2 : $t2";
say "T3 : $t3";
say "T4 : $t4";

# T1 : this has a $0 in it
# T2 : this has a $0 in it
# T3 : this has a $foo in it
# T4 : this has a switch in it

最佳答案

$replace之间的唯一区别和 {$replace}是第二个是返回变量值的块。它只是增加了一个间接级别,但结果是一样的。
更新 :根据@raiph 的评论进行编辑。

关于replace - 替换 : replacement evaluation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55771010/

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