I admit it I am completely baffled by the syntax of reading (retrieving values from) arrays of hashes. Defining them is easy enough but I'm missing something on the accessing side.

I'm trying to do a practical task, involving retrieving all the paths (in this case) (later messages) for a range of subversion revisions use SVN::Log;

I've declared (and invoked) the AoH/svn log retrieval for my repo and grabbed the data I'm interested in.

       my @revs=SVN::Log::retrieve($repoURL, $rev1, $rev2); # (svn::log declares the data structure described below)

Using komodo I can see that my array of hashes "@revs" contains this data structure and data:

--------- 1 @revs 2 ->[0] 3 ->[0] 4 ->{author} myid 5 ->{date} 2013-06-11 6 ->{message} CR-2020 Implement... 7 ->{paths} 8 ->{"/app/trunk/...} 9 ->{action} M 10 ->{revision} 31 11 ->[1] 12 ->[2] ... -------

I believe the array revs contains one member [0] which contains a hash %0 which contains 0-n keys each containing author, date, message(a hash), paths(a hash), revision.

Intuitively I want to extract %0 from the array and then work with the hash key/value pairs in that. I would use the %hash->{0}->{revision} to get "31" on line 10 or %hash->{0}->{paths}->{actions} to get to the M on line 9 above.

I don't understand how to work with the hashes when they are inside the array. Tried a bunch of things that basically resulted in "FAIL". Consulted a lot of tutorials (most notably and appreciated http://perldoc.perl.org/perldsc.html#HASHES-OF-ARRAYS section on Arrays of Hashes which was very well done but failed to get through my hard head).

But I think (judging by the data structure above) that my data is nested one level deeper than in the example. Am I being fooled by the extra level $0->{0}

I know $var=shift(@array) and $var=@array[0].
I know $var=%hash->{key} (probably better written as $hash->{key} which I accept but don't understand) The website above gives this example:

for $i ( 0 .. $#AoH ){ #I get this, for 0 - the total members count in the array of hashes for $role ( keys %{ $AoH[$i] } ) { # new variable $role defined to hold the keys print "elt $i $role is $AoH[$i]{$role}\n"; # print the hash index# the hash reference? is (value of $role) for t +hat index? } }

That example only seems to go three deep and I've got one more I think. Am I defining my array wrong?

So, though I understand arrays pretty well (I use them extensively) this is apparently beyond my meager skills.

How do I get to the paths and revisions out of the hash and into a variable so I can print them?

I really have spent about two days trying to sort this out on my own, (and that's not the first time I've tried to slay the hash dragon in my brain) but there's something here I just don't grok. Thank you in advance for considering my question.


In reply to Array of Hashes Svn::Log confusion by gj2666

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.