gpt4 book ai didi

arrays - 为什么这个函数显示的是一个数组的数组而不是一个数组?

转载 作者:行者123 更新时间:2023-12-02 16:37:47 25 4
gpt4 key购买 nike

use warnings;
use strict;

testfunc();
sub testfunc {
my @first_pin_name_list=qw(
VDD2_DDR2_S2_4
VDD1_DDR2_S2_2
);

my @second_pin_name_list=qw(
VDD2_DDR2_S2_4
VDD1_DDR2_S2_2
);
my @expected_list =qw(
VDD1_DDR0_S2_[2:1]
VDD2_DDR0_S2_[5:1]
);

my @listoftests = (
{INPUT_LIST => \@first_pin_name_list,OUTPUT_LIST => \@expected_list,OK_2_FAIL=> 0},
{INPUT_LIST => \@second_pin_name_list,OUTPUT_LIST => \@expected_list,OK_2_FAIL => 1}

);

print @expected_list;

# should show an array but instead debugger shows an array of an array
my @listtotest = $listoftests[0] -> {INPUT_LIST};
print "hello";
return @listoftests;
}

调试器显示 @listtotest 包含一个数组的数组,但我只想看到一个包含元素的数组。如何更改我的代码以仅显示一组元素?

最佳答案

您没有向我们展示调试器向您展示的内容,但没有数组的数组。

$listoftests[0]->{INPUT_LIST} 是对数组@first_pin_name_list 的引用。如果您想将该数组中的元素分配给 @listtotest,您需要取消引用它:

my @listtotest = $listoftests[0]->{INPUT_LIST}->@*;

或者在旧的 perls 上:

my @listtotest = @{ $listoftests[0]->{INPUT_LIST} };

关于arrays - 为什么这个函数显示的是一个数组的数组而不是一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62295362/

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