Let Pseudo and Logical be the two keys of a hash that you are seeking to populate as you read through each paragraph.

Write a regular expression with two captures, the first of which is either Pseudo and Logical and the second of which is what comes after the equal sign.

As soon as your hash has both the desired keys, you are ready to print its values and start over.

my @KEYS = qw( Pseudo Logical ); my $key_count = scalar @KEYS; my $key_alternation = join q{|}, @KEYS; my $key_value_pattern = qr/ ($key_alternation) # capture a key [^=]* # skip what is not an equal sign = # match the equal sign (.*\S) # capture the value /x; PARAGRAPH: while (not my %value_for) { LINE: while (<DATA>) { my ($key, $value) = /$key_value_pattern/; next LINE if !$key; $value_for{$key} = $value; if (scalar keys %value_for >= $key_count) { print join (q{, }, @value_for{@KEYS}), "\n"; next PARAGRAPH; } } # eof last PARAGRAPH; } __DATA__

With the given data, this prints

hdiskpower97, 0380 hdiskpower90, 0381

In reply to Re: help printing items across multiple lines - one regex, one hash, two keys by Narveson
in thread help printing items across multiple lines by exsnafu

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.