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.
Output: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.
Which gives us what we want, each book, each chapter and its verses.{ 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.", ], }, }, }
Output:# a form of toolic wisdom for ( sort { $a <=> $b } keys %{ $bible{'Genesis'}{'chapter 1'} } ) { +# updated print $_, ": ", @{ $bible{'Genesis'}{'chapter 1'}{$_} }, $/; }
Please check the reference initially stated above perldsc1: 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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |