<?xml version="1.0" encoding="windows-1252"?>
<node id="1010852" title="Re: join all elements in array reference by hash" created="2012-12-29 16:37:36" updated="2012-12-29 16:37:36">
<type id="11">
note</type>
<author id="918402">
2teez</author>
<data>
<field name="doctext">
&lt;p&gt;
Hi [johnko],&lt;br&gt;&lt;br&gt;

&lt;i&gt;"..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?.."&lt;/i&gt;&lt;br&gt;&lt;br&gt;
 I don't know how your data comes, but something like this could give a head up.&lt;br&gt;
&lt;c&gt;
use warnings;
use strict;

my %bible;
my $book;
my $chapter;

while (&lt;DATA&gt;) {
    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 of the deep. And the Spirit of God 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 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 his brothers.
John
chapter 1
1 In the beginning was the Word, and the Word was with God, and the Word was God.
2 He was in the beginning with God.
&lt;/c&gt; 

&lt;tt&gt;Output:&lt;/tt&gt;
&lt;c&gt;
{
  Exodus  =&gt; {
               "chapter 1" =&gt; {
                 1 =&gt; [
                        "Now these are the names of the children of Israel who came to Egypt; each man and his household came with Jacob:",
                      ],
                 2 =&gt; ["Reuben, Simeon, Levi, and Judah;"],
               },
             },
  Genesis =&gt; {
               "chapter 1" =&gt; {
                                1 =&gt; ["In the beginning God created the heavens and the earth."],
                                2 =&gt; [
                                       "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.",
                                     ],
                              },
               "chapter 2" =&gt; {
                                1 =&gt; [
                                       "Thus the heavens and the earth, and all the host of them, were finished. ",
                                     ],
                                2 =&gt; [
                                       "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.",
                                     ],
                              },
             },
  John    =&gt; {
               "chapter 1" =&gt; {
                 1 =&gt; [
                        "In the beginning was the Word, and the Word was with God, and the Word was God.",
                      ],
                 2 =&gt; ["He was in the beginning with God."],
               },
             },
  Matthew =&gt; {
               "chapter 1" =&gt; {
                 1 =&gt; [
                        "The book of the genealogy of Jesus Christ, the Son of David, the Son of Abraham:",
                      ],
                 2 =&gt; [
                        "Abraham begot Isaac, Isaac begot Jacob, and Jacob begot Judah and his brothers.",
                      ],
               },
             },
}

&lt;/c&gt;
Which gives us what we want, each book, each chapter and its verses.&lt;br&gt; Then knowing, the chapter and verses we want and using the wisdom of [toolic] we can access what we want.
&lt;br&gt; All things been equal, let say we want to see all the verses in Genesis, chapter 1.&lt;br&gt;
Let cheat a bit, like so:
&lt;c&gt;
# a form of toolic wisdom
for ( sort { $a &lt;=&gt; $b } keys %{ $bible{'Genesis'}{'chapter 1'} } ) { # updated
    print $_, ": ", @{ $bible{'Genesis'}{'chapter 1'}{$_} }, $/;
}
&lt;/c&gt;
&lt;tt&gt;Output:&lt;/tt&gt;&lt;br&gt;
&lt;c&gt;
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.

&lt;/c&gt;
Please check the reference initially stated above [doc://perldsc]&lt;br&gt;

&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-918402"&gt;
If you tell me, I'll forget.&lt;br&gt;
If you show me, I'll remember.&lt;br&gt;
if you involve me, I'll understand.&lt;br&gt;
--- Author [unknown to me]
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1010848</field>
<field name="parent_node">
1010848</field>
</data>
</node>
