Ich habe Probleme mit dem Zugriff auf einen Hash in jedem Element des Arrays nach dem Erstellen, aber es gab das letzte Element. Was muss ich tun, um auf alle Elemente meines Arrays zuzugreifen?Zugriff auf Array von Hash in Perl
@stem =();
for($i=0;$i<2;++$i){
push @stem,{u1=>1 , u2 => 2 , u3 => 3};
}
@ants =();
$count = 0;
for($i=0;$i<scalar(@stem);++$i){
@allowed =();
%hash =();
for($j=0;$j<scalar(@stem);++$j){
push @allowed,{stem=>++$count,hinfo=>++$count};
}
%hash = (allowed=>\@allowed ,solution=>++$count);
push (@ants,\%hash);
}
for($i=0;$i<scalar(@ants);++$i){
%test = %{$ants[$i]};
print "=>",$test{solution},"\n";
@temp = @{$test{allowed}};
for($j=0;$j<scalar(@temp);++$j){
print $j,":",$temp[$j]->{stem}," ",$temp[$j]->{hinfo},"\n";
}
}
output:
=> 21
0:16 16
1:18 18
2:20 20
=> 21
0:16 16
1:18 18
2:20 20
beginnen mit 'use strict; Verwenden Sie Warnungen; 'und verwenden Sie globale Variablen nicht überall. – melpomene