gj2666 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of Hashes Svn::Log confusion
by toolic (Bishop) on Jun 21, 2013 at 16:41 UTC | |
|
Re: Array of Hashes Svn::Log confusion
by NetWallah (Canon) on Jun 21, 2013 at 22:11 UTC | |
|
Re: Array of Hashes Svn::Log confusion
by gj2666 (Beadle) on Dec 01, 2014 at 20:41 UTC |