Where did keyword2 go? Perhaps this was a design decision. If not, adding the line @{$hash{$currentkey}} = (); into the if( $inkey == 0 ) block does the trick.

P.S.: In order to make Data::Dumper print very nice output, pass it a hash reference, as in Dumper(\%hash). Then the output is as follows:

$VAR1 = { 'mykeyword3' => [ 'baz3', 'foo3', 'bar3' ], 'mykeyword2' => [], 'mykeyword1' => [ 'foo1', 'bar1' ], 'mykeyword4' => [ 'baz4' ] };

P.P.S.: Can some enlightened monk tell me the preferred way to "touch" an array (reference). That is, if I only want to clear an array if it doesn't already exist (see my @{$hash{$currentkey}} = (); addition above). The snippet push @{$hash{$currentkey}}; works but produces a Useless use of push with no values warning.


In reply to Re^2: searching data lines between keywords by kaif
in thread searching data lines between keywords by riz

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!
  • 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:
    & &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.