Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi johnko,

"..Is this the right way to copy off the @verses array so that I can reuse it when parsing the next chapter? or will I have the same problem with @saved_verses being replaced with the new verses?.."

I don't know how your data comes, but something like this could give a head up.

use warnings; use strict; my %bible; my $book; my $chapter; while (<DATA>) { chomp; if ( /^[^0-9]/ and !/chapter/i ) { $book = $_; } elsif (/chapter/i) { $chapter = $_; } else { my ( $verse, $words ) = split /\s/, $_, 2; push @{ $bible{$book}{$chapter}{$verse} }, $words; } } use Data::Dump; dd \%bible; __DATA__ Genesis chapter 1 1 In the beginning God created the heavens and the earth. 2 The earth was without form, and void; and darkness was on the face o +f the deep. And the Spirit of God was hovering over the face of the w +aters. chapter 2 1 Thus the heavens and the earth, and all the host of them, were finis +hed. 2 And on the seventh day God ended His work which He had done, and He +rested on the seventh day from all His work which He had done. Exodus chapter 1 1 Now these are the names of the children of Israel who came to Egypt; + each man and his household came with Jacob: 2 Reuben, Simeon, Levi, and Judah; Matthew chapter 1 1 The book of the genealogy of Jesus Christ, the Son of David, the Son + of Abraham: 2 Abraham begot Isaac, Isaac begot Jacob, and Jacob begot Judah and hi +s brothers. John chapter 1 1 In the beginning was the Word, and the Word was with God, and the Wo +rd was God. 2 He was in the beginning with God.
Output:
{ Exodus => { "chapter 1" => { 1 => [ "Now these are the names of the children of Is +rael who came to Egypt; each man and his household came with Jacob:", ], 2 => ["Reuben, Simeon, Levi, and Judah;"], }, }, Genesis => { "chapter 1" => { 1 => ["In the beginning God created th +e heavens and the earth."], 2 => [ "The earth was without form, an +d void; and darkness was on the face of the deep. And the Spirit of G +od was hovering over the face of the waters.", ], }, "chapter 2" => { 1 => [ "Thus the heavens and the earth +, and all the host of them, were finished. ", ], 2 => [ "And on the seventh day God end +ed His work which He had done, and He rested on the seventh day from +all His work which He had done.", ], }, }, John => { "chapter 1" => { 1 => [ "In the beginning was the Word, and the Word w +as with God, and the Word was God.", ], 2 => ["He was in the beginning with God."], }, }, Matthew => { "chapter 1" => { 1 => [ "The book of the genealogy of Jesus Christ, th +e Son of David, the Son of Abraham:", ], 2 => [ "Abraham begot Isaac, Isaac begot Jacob, and J +acob begot Judah and his brothers.", ], }, }, }
Which gives us what we want, each book, each chapter and its verses.
Then knowing, the chapter and verses we want and using the wisdom of toolic we can access what we want.
All things been equal, let say we want to see all the verses in Genesis, chapter 1.
Let cheat a bit, like so:
# a form of toolic wisdom for ( sort { $a <=> $b } keys %{ $bible{'Genesis'}{'chapter 1'} } ) { +# updated print $_, ": ", @{ $bible{'Genesis'}{'chapter 1'}{$_} }, $/; }
Output:
1: In the beginning God created the heavens and the earth. 2: The earth was without form, and void; and darkness was on the face +of the deep. And the Spirit of God was hovering over the face of the +waters.
Please check the reference initially stated above perldsc

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: join all elements in array reference by hash by 2teez
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 lurking in the Monastery: (7)
    As of 2014-04-19 19:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (483 votes), past polls