PDA

View Full Version : Perl: nested arrays/hashes/references


cfan
08-04-2006, 06:17 AM
Hello,

I'm trying to extract useful data from a hash table that was returned by the Xerces P XML parser. Unfortunately, it contains lots of nested hashes, references, and arrays, and I'm getting lost in a sea of punctuation marks. Specifically, why am I able to do something like this:

$fileName = $hash->{"children"}[0]->{"children"}[$i]->{"text"};

for $i = 0..5, but when I write

my @arr = $hash->{"children"}[0]->{"children"};
print scalar(@arr) . "\n";

the output is 1? How do I get this to return the correct value of 6? (Right now, the iteration is just hard-coded, but I'd obviously like to make the length variable).

Thanks!

FishMonger
08-04-2006, 06:26 AM
Try this:
my @arr = @{ $hash->{"children"}[0]->{"children"} };

cfan
08-04-2006, 07:01 AM
Awesome. Thanks for the prompt help!

FishMonger
08-04-2006, 07:08 AM
You're welcome.