Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Perl: nested arrays/hashes/references

    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:

    Code:
    $fileName = $hash->{"children"}[0]->{"children"}[$i]->{"text"};
    for $i = 0..5, but when I write

    Code:
    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!

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Try this:
    my @arr = @{ $hash->{"children"}[0]->{"children"} };

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome. Thanks for the prompt help!

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You're welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •