O wise and learned monks of the perl (and particularly Christian persuasion), I seek wisdom on how to join all the elements of my array that I've referenced in a hash. I've parsed out sections of a text bible into a structure that I reference by book, chapter, and verse. I have tried to save my results to a hash that looks like:
...
my @saved_verses = @verses;
$bible{$book}{$chapter}{'verses'} = \@saved_verses;
@verses = (); # use again for next chapter
which I try to subsequently access to get either individual verses out, or to print all the verses in a particular chapter.
2 questions:
1. 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?
2. When trying to access all the verses of a particular chapter, how do I join all the verses? (i.e. I want all the verses in Genesis Chapter 1) I seem to be able to access individual verses but can't seem to join on the array:
my $n = 0;
$bible{$bookname}{$chapter}{'verses'}[$n];
# but neither of the following seem to work
join("\n\n",$bible{$bookname}{$chapter}{'verses'}[0..$#{$bible{"$b
+ookname"}{"$chapter"}{'verses'}}]);
join("\n\n",$bible{$bookname}{$chapter}{'verses'});
# I get instead ARRAY(0x[0-9]*) or Argument "" isn't numeric in ar
+ray element at ...
Hoping for a revelation on the proper procedures.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.