Hello perl monks, I am trying to loop through an array but am stuck pulling my hair out! Hoping you can assist. In the following example, it appears that the first loop cannot get the correct size of the first array; yet using similar code for the second it works fine
$arrref = $queryHandle->fetchall_arrayref(); $colnames = $queryHandle->{NAME}; print Dumper($colnames); print Dumper($arrref); print "A size:" . @colnames . "\n"; for ($i=0; $i < @colnames; $i++) { print "A: " . $i . " : " . $colnames[$i] ."\n"; } for ($i=0; $i<= @arrref; $i++) { print "B size:" . @{$arrref->[$i]} . "\n"; for ($j=0; $j< @{$arrref->[$i]}; $j++) { print "B: " . $i . " : " . $j . " : " . $arrref->[$i]->[$j] . +"\n"; } }
C:\temp>perl 1.pl $VAR1 = [ 'MEASURE', 'CNT' ]; $VAR1 = [ [ '# PLTADM Queries (ex batch) ', '0' ] ]; A size:0 B size:2 B: 0 : 0 : # PLTADM Queries (ex batch) B: 0 : 1 : 0
In reply to Looping through an Array by jarrodb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |