我通过引用一个子数组来传递一个数组,function(\@charts);
数组图表包含 i=0 处的哈希数组和 i=1 处的字符串等等(哈希字符串..)我想将哈希的键存储在 @x 和@y 中的值如下面的函数所示。但是我得到了一个无限循环;它一直在打印...
sub function{
print Dumper @_;
for ($i=0;$i<scalar @{$_[0]} ;$i+2)
{
@data= @{$_[$i]};
$title=$_[$i+1];
%hash =%{$data[$i]};
# print Dumper \%hash;
foreach my $key (sort { $a <=> $b} keys %hash) {
push (@x,$key);
push (@y,$hash{$key});
}
print Dumper @x;
}}
输出:
$VAR1 = [
{
'84' => 2,
'11' => 2,
'53' => 2,
'3' => 2,
'-46' => 2,
'14' => 2,
'-7' => 2,
'47' => 2,
'-10' => 2,
'0' => 2,
'72' => 2,
'-2' => 2
},
'1_-2_-2'
];
这是@x 无限循环
...$VAR21817 = '-46';
$VAR21818 = '-10';
$VAR21819 = '-7';
$VAR21820 = '-2';
$VAR21821 = '0';
$VAR21822 = '3';
$VAR21823 = '11';
$VAR21824 = '14';
$VAR21825 = '47';
$VAR21826 = '53';
$VAR21827 = '72';
$VAR21828 = '84';
$VAR21829 = '-46';
$VAR21830 = '-10';
$VAR21831 = '-7';
$VAR21832 = '-2';
$VAR21833 = '0';
$VAR21834 = '3';
$VAR21835 = '11';
$VAR21836 = '14';
$VAR21837 = '47';
$VAR21838 = '53';
$VAR21839 = '72';
$VAR21840 = '84';
$VAR21841 = '-46';
$VAR21842 = '-10';
$VAR21843 = '-7';
$VAR21844 = '-2';
$VAR21845 = '0';
$VAR21846 = '3';
$VAR21847 = '11';
$VAR21848 = '14';
$VAR21849 = '47';
$VAR21850 = '53';
$VAR21851 = '72';
$VAR21852 = '84';
问题出在哪里以及如何解决?提前致谢