http://qs321.pair.com?node_id=761672

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

Greetings, fellow monks;

I have a sub that needs to print out an array of arrays (or array of arrayrefs, depending on the version of my code), but for some reason foreach doesn't seem to select anything from the first array.

An example would perhaps clarify the problem more:

sub convFieldToXML($) { my $fldref = shift; print "fldref=\n"; dump($fldref); print "fldref[TXT]=\n"; dump(@$fldref[TXT]); if (ref(@$fldref[TXT]) eq 'ARRAY') { foreach my $tmp (@$fldref[TXT]) { print "tmp=\n"; dump($tmp); } } else { # snip --8<--; } }

Short fragment of output:

fldref= [ 500, 0, 0, [ ["\$a", "Tarina Babarista, pienest{ elefantista"], ["\$s", "(26'34); orkestroitu"], ["\$d", "Poulenc, Francis"], ["\$g", "Brunhoff, Jean de "], ["\$h", "P|ysti, Lasse"], ["\$j", "Fran*8aix, Jean"], ], ] fldref[TXT]= [ ["\$a", "Tarina Babarista, pienest{ elefantista"], ["\$s", "(26'34); orkestroitu"], ["\$d", "Poulenc, Francis"], ["\$g", "Brunhoff, Jean de "], ["\$h", "P|ysti, Lasse"], ["\$j", "Fran*8aix, Jean"], ] tmp= [ ["\$a", "Tarina Babarista, pienest{ elefantista"], ["\$s", "(26'34); orkestroitu"], ["\$d", "Poulenc, Francis"], ["\$g", "Brunhoff, Jean de "], ["\$h", "P|ysti, Lasse"], ["\$j", "Fran*8aix, Jean"], ]

Or also (with refs):

fldref= [ 500, 0, 0, [ \["\$a", "Tarina Babarista, pienest{ elefantista"], \["\$s", "(26'34); orkestroitu"], \["\$d", "Poulenc, Francis"], \["\$g", "Brunhoff, Jean de "], \["\$h", "P|ysti, Lasse"], \["\$j", "Fran*8aix, Jean"], ], ] fldref[TXT]= [ \["\$a", "Tarina Babarista, pienest{ elefantista"], \["\$s", "(26'34); orkestroitu"], \["\$d", "Poulenc, Francis"], \["\$g", "Brunhoff, Jean de "], \["\$h", "P|ysti, Lasse"], \["\$j", "Fran*8aix, Jean"], ] tmp= [ \["\$a", "Tarina Babarista, pienest{ elefantista"], \["\$s", "(26'34); orkestroitu"], \["\$d", "Poulenc, Francis"], \["\$g", "Brunhoff, Jean de "], \["\$h", "P|ysti, Lasse"], \["\$j", "Fran*8aix, Jean"], ]

Note that @$fldref[TXT] has the same output as $tmp, despite the foreach(). I expected $tmp to contain each array from the second level of array-of-arrays (or array-of-refs). Instead, foreach doesn't seem to select anything.

Help?