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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |