http://www.perlmonks.org?node_id=1010894


in reply to Re: join all elements in array reference by hash
in thread join all elements in array reference by hash

for ( keys %{ $bible{'Genesis'}{'chapter 1'} }) { print $_, ": ", @{ $bible{'Genesis'}{'chapter 1'}{$_} }, $/; }

That this loop prints your example data in the correct order is an artifact of the small number of verses in the data. Try adding the verses
    3 Three.
    4 Four.
    ...
    10 Ten.
to Genesis Chapter 1 and you will see the verses printed in apparently random order (really, the hashing order). Numerically sort the 'verse' keys before printing to get the correct order. (Tested.)

for (sort { $a <=> $b } keys %{ $bible{'Genesis'}{'chapter 1'} }) { print $_, ": ", @{ $bible{'Genesis'}{'chapter 1'}{$_} }, $/; }

Also, I would question your departure from the array-based nature of verse storage in the first place. johnko's OP example implies that each string/line is a verse and is stored in an array in verse order, and this is the way toolic's reply treats it. In your example, you store one and only one verse per anonymous array with the verse number as the hash key to the array, which seems a bit wasteful and, more importantly, potentially rather confusing. Are there, in fact, 'verses' that consist in more than one line of data?

I would also question how your book/chapter/verse parsing would handle books like "1 Corinthians", "2 Thessalonians", etc., but, as you say, this is all critically dependent on the exact format of the data johnko is parsing, which is not revealed to us.