http://www.perlmonks.org?node_id=1012884

jarrodb has asked for the wisdom of the Perl Monks concerning the following question:

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