[英]Why does a 2X1 array need to be defined as (1 to 2, 1 to 1) instead of just (1 to 2)
[英]Why does this function show an array of an array instead of just an array?
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
包含一個數組的數組,但我只想看到一個包含元素的數組。 如何更改我的代碼以僅顯示一組元素?
您沒有向我們展示調試器向您展示的內容,但沒有 arrays 數組。
$listoftests[0]->{INPUT_LIST}
是對數組@first_pin_name_list 的引用。 如果要將該數組中的元素分配給@listtotest
,則需要取消引用它:
my @listtotest = $listoftests[0]->{INPUT_LIST}->@*;
或者在舊的 perls 上:
my @listtotest = @{ $listoftests[0]->{INPUT_LIST} };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.