Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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.


In reply to Re^2: join all elements in array reference by hash by AnomalousMonk
in thread join all elements in array reference by hash by johnko

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (7)
    As of 2014-08-29 08:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (277 votes), past polls